Commit 5e6c0ce7 authored by Frank Terbeck's avatar Frank Terbeck

cdm: Use a tmux-user-option to keep track of session-specific cwds

parent dad784c9
......@@ -2,20 +2,44 @@
emulate -L zsh
setopt extendedglob
local tmp
local cfg new tmp
if [[ -z "${TMUX}" ]]; then
if (( $# == 1 )) && [[ "x$1" == "x-h" ]]; then
cat <<EOF
usage: cdm [-h] [DIRECTORY]
Switches the default working directory of a tmux session to DIRECTORY. If
DIRECTORY is not supplied, cdm changes zsh's current working directory to
the current tmux session's default working directory.
Internally, the function uses a tmux-user-option named "@ft-zsh-wd".
EOF
return 0
fi
if [[ -z "$TMUX" ]]; then
printf 'Not inside of `tmux'\''. Giving up.\n'
return 1
fi
if [[ -n "$1" ]]; then
[[ "$1" == . ]] && tmp="${PWD}" || tmp="$1"
if (( $# == 0 )); then
cfg=$(tmux show-options -v -q "@ft-zsh-wd")
if [[ -z $cfg ]]; then
new=$PWD
else
new=$cfg
fi
elif (( $# == 1 )); then
new=$1
else
tmp="${HOME}"
printf 'cdm: Too many arguments! Try the -h option!\n'
return 1
fi
cd "${tmp}"
tmp="${PWD}"
tmux "set-environment" "ZRC_PLEASE_GOTO" "${tmp}"
[[ -n "${DISPLAY}" ]] && tmp=on || tmp=off
tmux "set-option" "set-titles" "${tmp}"
new=${new:A}
[[ $new != $PWD ]] && cd $new
[[ $cfg != $new ]] && tmux set-option "@ft-zsh-wd" $new
[[ -n "$DISPLAY" ]] && tmp=on || tmp=off
tmux "set-option" "set-titles" "$tmp"
return 0
......@@ -2819,17 +2819,7 @@ bind2maps menuselect -- "^g" send-break
umask 0077
ulimit -c unlimited
if [[ -n ${ZRC_PLEASE_GOTO} ]] ; then
if [[ -d ${ZRC_PLEASE_GOTO} ]] ; then
zprintf 1 'Changing directory: %s\n' ${ZRC_PLEASE_GOTO}
cd ${ZRC_PLEASE_GOTO}
else
zprintf 1 'Could not change directory, as you requested.\n'
zprintf 1 'The directory does not exist: %s\n' ${ZRC_PLEASE_GOTO}
fi
else
zprintf 1 'Staying where we are: %s\n' ${PWD}
fi
[[ -n $TMUX ]] && cdm
### Post setup optional config file and profiling ############################
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment