]> git.mdlowis.com Git - projs/tide.git/commitdiff
rework edit script to support absolute paths
authorMichael D. Lowis <mike@mdlowis.com>
Thu, 13 Apr 2017 23:46:58 +0000 (19:46 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Thu, 13 Apr 2017 23:46:58 +0000 (19:46 -0400)
edit

diff --git a/edit b/edit
index 48fd6e0245482f8c1f1a9d73cb6fd8491b459430..2ce5ba5c683033c52dd30db38c97614d9895e369 100755 (executable)
--- a/edit
+++ b/edit
@@ -12,8 +12,15 @@ die() {
 # the new working directory.
 edit_relative_ctags(){
     origdir="$PWD"
-    origpath="$PWD/$1"
+    case "$1" in
+        /*) origpath="$1" ;;      # absoulte path given
+        *)  origpath="$PWD/$1" ;; # relative path given
+    esac
     path="${origpath##*/}"
+
+    # try to cd to the directory containing the file and attempt to walk the 
+    # tree backwars until we find a tags file. if one is found, open the file
+    # from that directory.
     cd "${origpath%/*}" || die "could not open file: '$1'"
     dir="$PWD"
     while [ "$dir" != "" ]; do
@@ -24,6 +31,8 @@ edit_relative_ctags(){
             dir="${dir%/*}"
         fi
     done
+
+    # file is not part of a project. open it as-is
     cd "$origdir" && exec nohup xedit "$1" > /dev/null 2>&1
 }