From 4ee6515b0f01b1eeafab7f2ebd2b433f98e272ab Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Mon, 27 Mar 2017 20:39:30 -0400 Subject: [PATCH] added logic to open target files with working dir set to root of containing projects --- edit | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/edit b/edit index 5fadad7..48fd6e0 100755 --- 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 -- 2.49.0