2018-04-03 15:55:41 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2018-04-30 17:19:00 +02:00
|
|
|
# If a window with a path in its title is focused, open a terminal with that
|
|
|
|
# location as working directory. Like this, terminals are opened in the same
|
2018-08-26 13:33:28 +02:00
|
|
|
# directory as the currently focused one. I modified my oh-my-zsh to always
|
|
|
|
# also print the directory, even when a command is executing.
|
2018-04-03 15:55:41 +02:00
|
|
|
|
2018-08-26 13:33:28 +02:00
|
|
|
if [[ $(xtitle) =~ (in|^.*@.*:)\ (~?)(/.*) ]]; then
|
2018-04-03 15:55:41 +02:00
|
|
|
path="${BASH_REMATCH[3]}"
|
|
|
|
[[ ${BASH_REMATCH[2]} == "~" ]] && path="$HOME$path"
|
|
|
|
|
|
|
|
while [[ $path != / && -n $path && ! -d $path ]]; do
|
|
|
|
path="$(dirname "$path")"
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Open terminal at specified path
|
|
|
|
cmd=i3-sensible-terminal
|
|
|
|
if [[ -n $path ]]; then
|
2018-08-19 16:48:28 +02:00
|
|
|
exec env -C "$path" $cmd "$@"
|
2018-04-03 15:55:41 +02:00
|
|
|
else
|
2018-07-12 00:46:51 +02:00
|
|
|
exec $cmd "$@"
|
2018-04-03 15:55:41 +02:00
|
|
|
fi
|