Skip to content

Instantly share code, notes, and snippets.

@ormaaj
Created March 16, 2016 18:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ormaaj/221b95dc27133c0b9eaf to your computer and use it in GitHub Desktop.
Save ormaaj/221b95dc27133c0b9eaf to your computer and use it in GitHub Desktop.
...
function getEnv {
${1:+\:} return 1
typeset -n name ret=$1
typeset -a names
compgen -e | mapfile -t names
set -- "${names[@]}"
for name; do
ret[${!name}]=$name
done
}
...
...
set +o posix
shopt -s extglob lastpipe
function main {
typeset myRootPath
if myRootPath=$(dirname "$(readlink -snf -- "$BASH_SOURCE")") && [[ -d $myRootPath ]]; then
source "${myRootPath}/functions" || return
unset -f main
else
return 1
fi
}
main
function tmuxUpdateGlobalEnv {
[[ $(type -t getEnv) == function && $TMUX ]] || return
[[ ${EUID:-$(id -u)} == 0 ]] && env-update
(
exec -c -- bash -O lastpipe -O extglob /dev/fd/3 "$(typeset -fp getEnv)" "$TMUX"
) 3<<-'EOF'
source /etc/profile
eval -- "$1" || exit
typeset -A _myEnv
getEnv _myEnv || exit
typeset _key
for _key in "${!_myEnv[@]}"; do
TMUX=$2 tmux setenv -g "$_key" "${_myEnv[$_key]}"
done
EOF
}
...
set-hook -g client-attached \
'run-shell -b "{ source ~ormaaj/doc/projects/dotfiles/common/home/shell/functions-tmux.ksh; tmuxupdateglobalenv; } 2>&1"'
bind -T prefix y if-shell -b \
'set -o pipefail && for _ in DISPLAY XAUTHORITY; do eval "$(tmux showenv -st #{session_id} "$_")"; done && tmux saveb - | xsel -d "${DISPLAY:-:0}" -i' \
'display "Sent tmux buffer to primary X selection."' \
'display "Failed setting selection."'
bind -T prefix C-p if-shell -b \
'set -o pipefail && for _ in DISPLAY XAUTHORITY; do eval "$(tmux showenv -st #{session_id} "$_")"; done && xsel -d "${DISPLAY:-:0}" -o | tmux loadb -' \
'display "Sent tmux buffer to primary X selection."' \
'display "Failed loading selection."'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment