Alain Leufroy avatar Alain Leufroy committed 86109a3

[sh] improve editor script

Comments (0)

Files changed (1)

             tmux select-window -t "$tmuxemacswindowname"
         fi
     fi
-    # try to interprete args (a.k.a. "path/to/file:5980: " as given by ``grep -n``)
-    line=$(echo $1 | sed 's/: *$//' | grep -E ':[0-9]+' | sed 's/^.*:\([0-9]\+\)/\1/')
+    # try to get x selection if no args given
+    if test "x" != "x$1"; then
+        inputfile="$1"
+    else
+        inputfile="$(xclip -o)"
+    fi
+    echo $inputfile
+    # try to interprete  (a.k.a. "path/to/file:5980: " as given by ``grep -n``)
+    line=$(echo $inputfile | sed 's/: *$//' | grep -E ':[0-9]+' | sed 's/^.*:\([0-9]\+\)/\1/')
     if test "x" != "x$line"; then
-        filepath=$(echo $1 | sed 's/:.*$//' )
-        /usr/bin/emacsclient -n +$line $filepath
+        filepath=$(echo $inputfile | sed 's/:.*$//' )
+        /usr/bin/emacsclient -aemacs -s$PROJECT -n +$line $filepath
     else
-        /usr/bin/emacsclient -n $@
+        /usr/bin/emacsclient -aemacs -s$PROJECT -n $@
     fi
 }
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.