]> git.mdlowis.com Git - projs/tide.git/commitdiff
added logic to open target files with working dir set to root of containing projects
authorMichael D. Lowis <mike@mdlowis.com>
Tue, 28 Mar 2017 00:39:30 +0000 (20:39 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Tue, 28 Mar 2017 00:39:30 +0000 (20:39 -0400)
edit

diff --git a/edit b/edit
index 5fadad7a2a8d871801c95a89f4323521b831d7cb..48fd6e0245482f8c1f1a9d73cb6fd8491b459430 100755 (executable)
--- a/edit
+++ b/edit
@@ -1,27 +1,30 @@
 #!/bin/sh
 
+# exits with error message
+die() {
+    printf "error: %s\n" "$@"
+    exit 1
+}
+
 # search for a ctags file recursively up the directory tree from the file to be 
 # opened. If one is found, change the working directory of the new process to
 # the containing folder and launch xedit with the path of the file relative to  
 # the new working directory.
 edit_relative_ctags(){
-    file="$(realpath -m "$1")"
-    path="$(basename "$file")"
-    dir="$(dirname "$file")"
-    while [ "$dir" != "/" ]; do
-        if [ -f "$dir/tags" ]; then
-            cd "$dir"
-            (nohup xedit "$path" > /dev/null 2>&1) &
-            #echo "cd to $dir" >2
-            #cd "$dir"
-            #echo "$path"
-            return 0
+    origdir="$PWD"
+    origpath="$PWD/$1"
+    path="${origpath##*/}"
+    cd "${origpath%/*}" || die "could not open file: '$1'"
+    dir="$PWD"
+    while [ "$dir" != "" ]; do
+        if [ -f "$dir/tags" ]; then 
+            cd "$dir" && exec nohup xedit "$path" > /dev/null 2>&1
         else
-            path="$(basename "$dir")/$path"
-            dir="$(dirname "$dir")"
+            path="${dir##*/}/$path"
+            dir="${dir%/*}"
         fi
     done
-    (nohup xedit "$1" > /dev/null 2>&1) &
+    cd "$origdir" && exec nohup xedit "$1" > /dev/null 2>&1
 }
 
 # Add the editing tools directory to your PATH var so its contents may be used