Created
February 11, 2015 02:18
-
-
Save dahu/c38092e54ec7c6ef7132 to your computer and use it in GitHub Desktop.
Expand bash brace forms in Vim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Barry Arthur, Feb 2015 | |
" Expand a bash brace expression | |
let x = 'xorg-{,xinit,xfontsel,xset,xrdb,font-util{,s},server{,-utils,},utils,xmodmap,xwininfo}' | |
function! BashBracesToVimTree(string) | |
return eval('[' . | |
\ tr(substitute(substitute(substitute(substitute(a:string, "'", "''", 'g') | |
\ , '[^,{}]\+', "'&'", 'g') | |
\ , "'{", "',{", 'g') | |
\ , "{,", "{", 'g') | |
\ , '{}', '[]') | |
\ . ']') | |
endfunction | |
function! ExpandTree(tree, ...) | |
let parent = a:0 ? a:1 : '' | |
let s = [] | |
for elem in a:tree | |
if type(elem) == type([]) | |
let prior = s[-1] | |
if parent == '' | |
call remove(s, -1) | |
endif | |
call add(s, ExpandTree(elem, prior)) | |
else | |
call add(s, parent . elem) | |
endif | |
unlet elem | |
endfor | |
return join(s) | |
endfunction | |
echo ExpandTree(BashBracesToVimTree(x)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment