summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2017-12-16 00:06:41 -0500
committerAndrew Cady <d@jerkface.net>2017-12-16 00:06:41 -0500
commit1cf925c91f27cca67cb641a602d98599a4228639 (patch)
tree27d24cd424413de15946e8e734dd7db3c6977dcc
parent3fee359f05c4fa0d4e3e5af81bba1485a212ceec (diff)
new command 'xchdir' launches xterm with specified cwd
-rwxr-xr-xdot/local/bin/xchdir39
1 files changed, 39 insertions, 0 deletions
diff --git a/dot/local/bin/xchdir b/dot/local/bin/xchdir
new file mode 100755
index 0000000..574b187
--- /dev/null
+++ b/dot/local/bin/xchdir
@@ -0,0 +1,39 @@
1#!/bin/bash
2err_script()
3{
4 if [ "$2" ]; then
5 msg="Error: could not change to directory '$1': $2"
6 else
7 msg="Error: could not change to directory '$1'."
8 fi
9 printf "printf '%s\n' %q\n" "$msg"
10 cat <<EOF
11echo Press enter to quit.
12read
13EOF
14}
15
16target=$1
17errmsg=
18case "$target" in
19 file:///) target=${target#file://} ;;
20esac
21
22try_chdir()
23{
24 if [ -d "$target" ]; then
25 cd "$target"
26 elif [ -e "$target" ]; then
27 cd "$(dirname "$target")"
28 else
29 errmsg='does not exist'
30 false
31 fi
32}
33
34if try_chdir; then
35 exec xterm
36else
37 err_script=$(err_script "$target" "$errmsg")
38 exec xterm -e "$err_script"
39fi