about summary refs log tree commit diff stats
path: root/nix-conf
diff options
context:
space:
mode:
authorDavid Morgan <djm_uk@protonmail.com>2024-09-18 15:05:41 +0000
committerDavid Morgan <djm_uk@protonmail.com>2024-09-18 15:05:41 +0000
commit3ea67299f3efb9a84e06d67e0c3479e157dad039 (patch)
treee0ff0394d6868940bc507232f79815cc77b71c05 /nix-conf
parent080baddeef577bfa1828e552aade8325d54483c6 (diff)
downloaddotfiles-3ea67299f3efb9a84e06d67e0c3479e157dad039.tar.gz
Improve ea functions
Diffstat (limited to 'nix-conf')
-rw-r--r--nix-conf/home/includes/zsh.nix20
1 files changed, 14 insertions, 6 deletions
diff --git a/nix-conf/home/includes/zsh.nix b/nix-conf/home/includes/zsh.nix
index 0003062..db17933 100644
--- a/nix-conf/home/includes/zsh.nix
+++ b/nix-conf/home/includes/zsh.nix
@@ -210,21 +210,29 @@ in
       # vip  # edits the first result from ea (roughly equivalent to vi `ea p 1`)
       # vip <n> # edits the nth result from ea (vi `ea p <n>`)
       # vip <n> foo # if the nth result from ea is a directory, edit foo in that directory (vi `ea p <n>`/foo)
+      # Will add +<line-number>, where the line number is available
       function _vip () {
-        CMD=(''${=1}) # zsh only, not portable; something like CMD=($(echo $1)) is more portable but is ugly
-        BASE_PATH=$(ea p ''${2:-1})
+        local cmd=(''${=1}) # zsh only, not portable; something like CMD=($(echo $1)) is more portable but is ugly
+        local idx=''${2:-1}
+        local base_path=$(ea p $idx)
+        local line=$(ea p $idx "{line}")
+        local ea_format="'{path}'"
 
-        if [ -z "$BASE_PATH" ]; then
+        if [ -z "$base_path" ]; then
           echo "No file path found for index $2"
           return 1
         fi
 
-        if [ $# -gt 2 -a ! -d "$BASE_PATH" ]; then
-          echo "$BASE_PATH is not a directory"
+        if [ $# -gt 2 -a ! -d "$base_path" ]; then
+          echo "$base_path is not a directory"
           return 2
         fi
 
-        $CMD "''${BASE_PATH}''${3}"
+        if [ $# -lt 3 -a $line -ne 1 ]; then
+          ea_format+=" +{line}"
+        fi
+
+        eval $(ea p $idx "$cmd ''${ea_format}$3")
       }
 
       function vip () {