#!/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