From: Michael D. Lowis Date: Tue, 28 Mar 2017 00:39:30 +0000 (-0400) Subject: added logic to open target files with working dir set to root of containing projects X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=4ee6515b0f01b1eeafab7f2ebd2b433f98e272ab;p=projs%2Ftide.git added logic to open target files with working dir set to root of containing projects --- 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