Skip to content

Instantly share code, notes, and snippets.

@haolian9
Created December 24, 2015 07:34
Show Gist options
  • Save haolian9/1632dc562d619506944e to your computer and use it in GitHub Desktop.
Save haolian9/1632dc562d619506944e to your computer and use it in GitHub Desktop.
# 读取管道中传递的文件, 并用vim打开
function vip
{ # {{{
local lines=''
# 从管道中读取
while read x; do
if [[ ! "${x}" ]]; then continue; fi
# 绝对路径, 忽略文件夹
x="$(realpath $x)"
if [[ -d "${x}" ]]; then continue; fi
lines="${lines} #~# $x"
done
if [[ ! "${lines}" ]]; then return 2; fi
local manner="$1"
case $manner in
--each)
for i in $(echo $lines | sed 's/#~#/\n/g'); do
vim -c "args ${i}" -
done
;;
*)
local string=$(echo $lines | sed 's/#~#/ /g');
vim -c "args ${string}" -
;;
esac
} # }}}
# use case:
# ag 'somepattern' -l | vip
# ag 'somepattern' -l | vip --each
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment