Skip to content

Instantly share code, notes, and snippets.

@ormaaj ormaaj/functions
Created Mar 16, 2016

Embed
What would you like to do?
...
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
You can’t perform that action at this time.