path-shorten
Simple path shortener
Easy to use
const pathShorten = consoleconsoleconsole
/one/two/thr/fou/five.txt
c/Use/mol/Doc/some-project
~/foo/bar
Why
To transform paths to the gist and reduce clutter.
How
Simple string manipulation.
Usage
const pathShorten = // default optionsconst opts = home: true // attempt to transform homedir to '~' homedir: length: 3 // path truncation max length // optional post transformation function ( for each url found in text )opts { return '[ ' + url + ' ]'} const text = 'text with /path/like/stuff.txt'console
text with [ /pat/lik/stuff.txt ]
vim
's pathshorten
( but not identical )
Similar to pathshorten({expr}) pathshorten()
Shorten directory names in the path {expr} and return the
result. The tail, the file name, is kept as-is. The other
components in the path are reduced to ${ opts.length || 3 } letters. Leading
'~' and '.' characters are kept.
Example:
:echo pathshorten('~/.vim/autoload/myfile.vim')
~/.v/a/myfile.vim
It doesn't matter if the path exists or not.
Test
npm test