]> git.mdlowis.com Git - projs/tide.git/commitdiff
Updated edit script to open files relative to the dir containing the project's ctags...
authorMichael D. Lowis <mike.lowis@gentex.com>
Mon, 27 Mar 2017 13:35:18 +0000 (09:35 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Mon, 27 Mar 2017 13:35:18 +0000 (09:35 -0400)
TODO.md
edit

diff --git a/TODO.md b/TODO.md
index 46917f61f5780e405ab81a3a5eb5244817083883..bc696bef66bcd03611e5eb94a1c80786c0f450dd 100644 (file)
--- a/TODO.md
+++ b/TODO.md
@@ -2,30 +2,29 @@
 
 Up Next:
 
-* update edit to cd to dir containing tags file if it exists
+* clipboard does not persist after exit
+* Run commands in the background and don't block the main thread.
 * Make Fn keys execute nth command in the tags buffer
 
 * check for file changes on save
 * check for file changes when window regains focus
 * Right click in tags region should search edit region
 * 100% coverage with unit and unit-integration tests
-* selecting text should set PRIMARY x11 selection
 * Add a SaveAs tag that takes an argument for the filename to save as
 * Add a GoTo tag for ctags lookup and line number jump (or right click magic?) 
 * Add keyboard shortcut to highlight the thing under the cursor
 * right click to fetch file or line
+* selecting text should set PRIMARY x11 selection
 
 Straight-up Bugs:
 
 * ctrl+space selects too large of a word in some cases (function names followed by paren)
-* tab inserts dont coalesce like one would expect
 * off by one error on scrolling up with wrapped lines
 * Ctrl+u with a selection clears to bol *before* selected text
-* clipboard does not persist after exit
+* tab inserts dont coalesce like one would expect
 
 The Future:
 
-* Run commands in the background and don't block the main thread.
 * shortcut to repeat previous operation
 * add command line flags to toggle options (Tabs, Indent, etc..)
 * add command env vars to set options (Tabs, Indent, etc..)
diff --git a/edit b/edit
index b4b53dd7d183cba4939665b21bd22db0af80c131..5fadad7a2a8d871801c95a89f4323521b831d7cb 100755 (executable)
--- a/edit
+++ b/edit
@@ -1,5 +1,29 @@
 #!/bin/sh
 
+# 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
+        else
+            path="$(basename "$dir")/$path"
+            dir="$(dirname "$dir")"
+        fi
+    done
+    (nohup xedit "$1" > /dev/null 2>&1) &
+}
+
 # Add the editing tools directory to your PATH var so its contents may be used
 # while editing.
 export PATH="$HOME/.config/edit/tools:$PATH"
@@ -25,6 +49,6 @@ elif [ 0 -eq $# ]; then
     (nohup xedit > /dev/null 2>&1) &
 else
     for f in "$@"; do
-        (nohup xedit "$f" > /dev/null 2>&1) &
+        edit_relative_ctags "$f" &
     done
 fi