Created
December 24, 2015 07:34
-
-
Save haolian9/1632dc562d619506944e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# 读取管道中传递的文件, 并用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