From 0d405e88642a88b8c8087eae4e8a41b8bccdd137 Mon Sep 17 00:00:00 2001 From: viktorbarzin Date: Sun, 13 Oct 2019 23:47:59 +0100 Subject: [PATCH] Oct 2019 updates --- .bash_aliases | 67 ++- .tmux.conf | 347 +++++++---- .tmux.conf.local | 113 ++-- .vimrc | 28 +- .zshenv | 15 - .zshrc | 16 +- virtualenvwrapper.sh | 1352 ++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 1758 insertions(+), 180 deletions(-) delete mode 100644 .zshenv create mode 100644 virtualenvwrapper.sh diff --git a/.bash_aliases b/.bash_aliases index 4ded4d1..36db643 100644 --- a/.bash_aliases +++ b/.bash_aliases @@ -3,6 +3,7 @@ alias grep='grep --color=auto' alias fgrep='fgrep --color=auto' alias egrep='egrep --color=auto' alias py='python3' +alias ipy='ipython3' alias whatisopen='sudo netstat -pnlt' alias calc='gcalccmd' alias pmr='python manage.py runserver' @@ -11,7 +12,7 @@ alias pmm='python manage.py migrate' alias pmmm='python manage.py makemigrations' # Start vim with system clipboard -# alias vim="vimx" # don't alias this - make symlink instead +alias vim="vimx" # don't alias this - make symlink instead alias vi="vim" # git aliases @@ -32,7 +33,7 @@ alias randomstr="tr -dc a-z1-4 /dev/null; tldr" alias sl=ls alias vimrc="vim ~/.vimrc" +alias zshrc="vim ~/.zshrc" alias f="free -h" alias h="sudo htop" +alias a="sudo atop" alias e="exa -bghHliS" alias hosts="sudo vim /etc/hosts" @@ -348,6 +354,51 @@ function encrypt() { gpg --symmetric $1.tar.gz echo "Deleting $1 and $1.tar.gz" rm -rf $1 $1.tar.gz - - +} + +function decrypt() { + gpg --decrypt $1 | tar xzvf - +} + +alias kb=kubectl + +# use avr-gcc for latfortuna, but gcc works as well +function make_tags() { +avr-gcc -M $* | sed -e 's/[\\ ]/\n/g' | \ + sed -e '/^$/d' -e '/\.o:[ \t]*$/d' | ctags -L - --c++-kinds=+p --fields=+iaS --extra=+q +} +#alias server="python3 -m http.server --bind 0.0.0.0 8000" +alias server="/opt/miniserve-linux" +alias gr="go run" +alias hg="hugo -D server --bind 0.0.0.0" +alias logout="qdbus org.kde.ksmserver /KSMServer logout 0 0 0" +alias sucss="cd ~/pentesting/sucss-19 && workon sucss-playground-webapp" +alias i="sudo iotop" +alias ssucss="ssh sucss.ecs.soton.ac.uk" +alias gpc="globalprotect connect; sudo sed -i '1 i\\nameserver 152.78.110.110' /etc/resolv.conf" +alias gpd="globalprotect disconnect; sudo sed -i '1d' /etc/resolv.conf" + +function whoishome() { + # echo "Finding connected devices..." + ips=$(nmap -sn 192.168.0.1/24 | grep for | awk '{print $5}') + + # echo "Getting entries from ARP table..." + # Get entries in arp table + python3 -c ' +import sys +users={ + "C8:21:58:98:29:25": "lubo-laptop", + "2C:0E:3D:A7:C1:19": "viktor-phone", + "18:F0:E4:2A:CB:B0": "lubo-phone", + "A0:32:99:C4:0E:38": "nasko-phone", + "48:01:C5:39:A6:3D": "ioana-phone", + "48:89:E7:18:0E:66": "viktor-laptop", +} +# print("Connected device: ") +for line in sys.argv[1].split("\n"): + ip = line.split()[1].replace("(", "").replace(")", "") + mac = line.split()[3].upper() + if mac in users: + print(f"{users[mac]}") +' "$(arp -a | grep -v incomplete)" } diff --git a/.tmux.conf b/.tmux.conf index a43f112..028024f 100644 --- a/.tmux.conf +++ b/.tmux.conf @@ -9,7 +9,6 @@ # -- general ------------------------------------------------------------------- -set -g default-shell /usr/bin/zsh set -g default-terminal "screen-256color" # colors! setw -g xterm-keys on set -s escape-time 10 # faster command sequences @@ -33,17 +32,13 @@ bind r source-file ~/.tmux.conf \; display '~/.tmux.conf sourced' # -- display ------------------------------------------------------------------- -set -g base-index 1 # start windows numbering at 1 -setw -g pane-base-index 1 # make pane numbering consistent with windows +set -g base-index 1 # start windows numbering at 1 +setw -g pane-base-index 1 # make pane numbering consistent with windows -setw -g automatic-rename on # rename window to reflect current program -set -g renumber-windows on # renumber windows when a window is closed +setw -g automatic-rename on # rename window to reflect current program +set -g renumber-windows on # renumber windows when a window is closed -set -g set-titles off # set terminal title -# set -g set-titles on # set terminal title -# set -g set-titles-string '#h ❐ #S ● #I #W' -# set -g set-titles-string '#h #S #I #W' -# set -g set-titles-string '#{client_name} | #{host}"' +set -g set-titles on # set terminal title set -g display-panes-time 800 # slightly longer pane indicators display time set -g display-time 1000 # slightly longer status messages display time @@ -61,12 +56,11 @@ set -g visual-activity off # -- navigation ---------------------------------------------------------------- # create session -#bind C-c new-session +bind C-c new-session # find session bind C-f command-prompt -p find-session 'switch-client -t %%' -set-window-option -g status-left " #S " # split current window horizontally bind - split-window -v # split current window vertically @@ -81,7 +75,7 @@ bind > swap-pane -D # swap current pane with the next one bind < swap-pane -U # swap current pane with the previous one # maximize current pane -bind + run 'cut -c3- ~/.tmux.conf | sh -s _maximize_pane #{session_name} #D' +bind + run 'cut -c3- ~/.tmux.conf | sh -s _maximize_pane "#{session_name}" #D' # pane resizing bind -r H resize-pane -L 2 @@ -144,9 +138,12 @@ run -b 'tmux bind -T copy-mode-vi y send -X copy-selection-and-cancel 2> /dev/nu run -b 'tmux bind -t vi-copy Escape cancel 2> /dev/null || true' run -b 'tmux bind -T copy-mode-vi Escape send -X cancel 2> /dev/null || true' run -b 'tmux bind -t vi-copy H start-of-line 2> /dev/null || true' +run -b 'tmux bind -T copy-mode-vi H send -X start-of-line 2> /dev/null || true' +run -b 'tmux bind -t vi-copy L end-of-line 2> /dev/null || true' run -b 'tmux bind -T copy-mode-vi L send -X end-of-line 2> /dev/null || true' -# copy to Mac OSX clipboard +# copy to macOS clipboard +if -b 'command -v pbcopy > /dev/null 2>&1' 'bind y run -b "tmux save-buffer - | pbcopy"' if -b 'command -v reattach-to-user-namespace > /dev/null 2>&1' 'bind y run -b "tmux save-buffer - | reattach-to-user-namespace pbcopy"' # copy to X11 clipboard if -b 'command -v xsel > /dev/null 2>&1' 'bind y run -b "tmux save-buffer - | xsel -i -b"' @@ -171,6 +168,7 @@ if '[ -f ~/.tmux.conf.local ]' 'source ~/.tmux.conf.local' # -- 8< ------------------------------------------------------------------------ run 'cut -c3- ~/.tmux.conf | sh -s _apply_configuration' +run -b '[ -z "#{session_id}" ] && [ -z "#{version}" ] && tmux set display-time 3000 \; display "This configuration will soon require tmux >= 2.4" \; set -u display-time || true' # EOF @@ -178,6 +176,18 @@ run 'cut -c3- ~/.tmux.conf | sh -s _apply_configuration' # # exit the script if any statement returns a non-true return value # set -e # +# unset GREP_OPTIONS +# export LC_NUMERIC=C +# +# if ! printf '' | sed -E 's///' 2>/dev/null; then +# if printf '' | sed -r 's///' 2>/dev/null; then +# sed () { +# n=$#; while [ "$n" -gt 0 ]; do arg=$1; shift; case $arg in -E*) arg=-r${arg#-E};; esac; set -- "$@" "$arg"; n=$(( n - 1 )); done +# command sed "$@" +# } +# fi +# fi +# # __newline=' # ' # @@ -185,7 +195,7 @@ run 'cut -c3- ~/.tmux.conf | sh -s _apply_configuration' # ( ([ x"$1" = x"enabled" ] || [ x"$1" = x"true" ] || [ x"$1" = x"yes" ] || [ x"$1" = x"1" ]) && return 0 ) || return 1 # } # -# _circled_digit() { +# _circled() { # circled_digits='⓪ ① ② ③ ④ ⑤ ⑥ ⑦ ⑧ ⑨ ⑩ ⑪ ⑫ ⑬ ⑭ ⑮ ⑯ ⑰ ⑱ ⑲ ⑳' # if [ "$1" -le 20 ] 2>/dev/null; then # i=$(( $1 + 1 )) @@ -196,28 +206,46 @@ run 'cut -c3- ~/.tmux.conf | sh -s _apply_configuration' # fi # } # +# if command -v perl > /dev/null 2>&1; then +# _decode_unicode_escapes() { +# printf '%s' "$*" | perl -CS -pe 's/(\\u([0-9A-Fa-f]{1,4})|\\U([0-9A-Fa-f]{1,8}))/chr(hex($2.$3))/eg' 2>/dev/null +# } +# elif bash --norc --noprofile -c '[[ ! $BASH_VERSION < 4.2. ]]' > /dev/null 2>&1; then +# _decode_unicode_escapes() { +# bash --norc --noprofile -c "printf '%b' '$*'" +# } +# elif command -v python > /dev/null 2>&1; then +# _decode_unicode_escapes() { +# python -c "import re; import sys; sys.stdout.write(re.sub(r'\\\U([0-9A-Fa-f]{1,8})', lambda match: r'\U%s' % match.group(1).zfill(8), r'$*').encode().decode('unicode-escape', 'ignore'))" +# } +# else +# _decode_unicode_escapes() { +# printf '%b' "$*" +# } +# fi +# # _maximize_pane() { # current_session=${1:-$(tmux display -p '#{session_name}')} # current_pane=${2:-$(tmux display -p '#{pane_id}')} # -# dead_panes=$(tmux list-panes -s -t "$current_session" -F '#{pane_dead} #{pane_id} #{pane_start_command}' | grep -o '^1 %.\+maximized.\+$' || true) -# restore=$(echo "$dead_panes" | sed -n -E -e "s/^1 $current_pane .+maximized.+(%[0-9]+)$/tmux swap-pane -s \1 -t $current_pane \; kill-pane -t $current_pane/p" -e "s/^1 (%[0-9]+) .+maximized.+$current_pane$/tmux swap-pane -s \1 -t $current_pane \; kill-pane -t \1/p" ) +# dead_panes=$(tmux list-panes -s -t "$current_session" -F '#{pane_dead} #{pane_id} #{pane_start_command}' | grep -E -o '^1 %.+maximized.+$' || true) +# restore=$(echo "$dead_panes" | sed -n -E -e "s/^1 $current_pane .+maximized.+'(%[0-9]+)'$/tmux swap-pane -s \1 -t $current_pane \; kill-pane -t $current_pane/p" -e "s/^1 (%[0-9]+) .+maximized.+'$current_pane'$/tmux swap-pane -s \1 -t $current_pane \; kill-pane -t \1/p" ) # # if [ -z "$restore" ]; then # [ "$(tmux list-panes -t "$current_session:" | wc -l | sed 's/^ *//g')" -eq 1 ] && tmux display "Can't maximize with only one pane" && return -# window=$(tmux new-window -t "$current_session:" -P "exec maximized... 2> /dev/null & tmux setw -t $current_session: remain-on-exit on; printf 'Pane has been maximized, press + to restore. %s' \\$current_pane") +# window=$(tmux new-window -t "$current_session:" -P "exec maximized... 2> /dev/null & tmux setw -t \"$current_session:\" remain-on-exit on; printf \"Pane has been maximized, press + to restore. %s\" '$current_pane'") # window=${window%.*} # -# guard=10 -# while [ x"$(tmux list-panes -t "$window" -F '#{session_name}:#{window_index} #{pane_dead}' 2>/dev/null)" != x"$window 1" ] && [ "$guard" -ne 0 ]; do -# sleep 0.01 -# guard=$((guard - 1)) +# retry=10 +# while [ x"$(tmux list-panes -t "$window" -F '#{session_name}:#{window_index} #{pane_dead}' 2>/dev/null)" != x"$window 1" ] && [ "$retry" -ne 0 ]; do +# sleep 0.05 +# retry=$((retry - 1)) # done -# if [ "$guard" -eq 0 ]; then +# if [ "$retry" -eq 0 ]; then # tmux display 'Unable to maximize pane' # fi # -# new_pane=$(tmux display -p '#{pane_id}') +# new_pane=$(tmux display -t "$window" -p '#{pane_id}') # tmux setw -t "$window" remain-on-exit off \; swap-pane -s "$current_pane" -t "$new_pane" # else # $restore || tmux kill-pane @@ -239,6 +267,7 @@ run 'cut -c3- ~/.tmux.conf | sh -s _apply_configuration' # } # # _battery() { +# count=0 # charge=0 # uname_s=$(uname -s) # case "$uname_s" in @@ -256,6 +285,8 @@ run 'cut -c3- ~/.tmux.conf | sh -s _apply_configuration' # ;; # *Linux*) # while IFS= read -r batpath; do +# grep -i -q device "$batpath/scope" 2> /dev/null && continue +# # if [ x"$discharging" != x"true" ]; then # discharging=$(grep -qi "discharging" "$batpath/status" && echo "true" || echo "false") # fi @@ -301,7 +332,7 @@ run 'cut -c3- ~/.tmux.conf | sh -s _apply_configuration' # done # ;; # esac -# charge=$(awk -v charge="$charge" -v count="$count" 'BEGIN { print charge / count }') +# [ "$count" -ne 0 ] && charge=$(awk -v charge="$charge" -v count="$count" 'BEGIN { print charge / count }') # if [ "$charge" -eq 0 ]; then # tmux set -ug '@battery_status' \;\ # set -ug '@battery_bar' \;\ @@ -354,7 +385,7 @@ run 'cut -c3- ~/.tmux.conf | sh -s _apply_configuration' # [ x"$palette_style" = x"gradient" ] && \ # palette="196 202 208 214 220 226 190 154 118 82 46" # [ x"$palette_style" = x"heat" ] && \ -# palette="233 234 235 237 239 241 243 245 247 144 143 142 184 214 208 202 196" +# palette="243 245 247 144 143 142 184 214 208 202 196" # # palette=$(echo "$palette" | awk -v n="$battery_bar_length" '{ for (i = 0; i < n; ++i) printf $(1 + (i * NF / n))" " }') # eval set -- "$palette" @@ -453,60 +484,91 @@ run 'cut -c3- ~/.tmux.conf | sh -s _apply_configuration' # set -g '@battery_percentage' "$battery_percentage" # } # +# _tty_info() { +# tty="${1##/dev/}" +# uname -s | grep -q "CYGWIN" && cygwin=true +# +# if [ x"$cygwin" = x"true" ]; then +# ps -af | tail -n +2 | awk -v tty="$tty" ' +# ((/ssh/ && !/-W/) || !/ssh/) && $4 == tty { +# user[$2] = $1; parent[$2] = $3; child[$3] = $2 +# } +# END { +# for (i in user) +# { +# if (!(i in child) && parent[i] != 1) +# { +# file = "/proc/" i "/cmdline"; getline command < file; close(file) +# gsub(/\0/, " ", command) +# print i, user[i], command +# exit +# } +# } +# } +# ' +# else +# ps -t "$tty" -o user=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -o pid= -o ppid= -o command= | awk ' +# NR > 1 && ((/ssh/ && !/-W/) || !/ssh/) { +# user[$2] = $1; parent[$2] = $3; child[$3] = $2; for (i = 4 ; i <= NF; ++i) command[$2] = i > 4 ? command[$2] FS $i : $i +# } +# END { +# for (i in parent) +# { +# if (!(i in child) && parent[i] != 1) +# { +# print i, user[i], command[i] +# exit +# } +# } +# } +# ' +# fi +# } +# +# _ssh_or_mosh_args() { +# args=$(printf '%s' "$1" | awk '/ssh/ && !/vagrant ssh/ && !/autossh/ && !/-W/ { $1=""; print $0; exit }') +# if [ -z "$args" ]; then +# args=$(printf '%s' "$1" | grep 'mosh-client' | sed -E -e 's/.*mosh-client -# (.*)\|.*$/\1/' -e 's/-[^ ]*//g' -e 's/\d:\d//g') +# fi +# +# printf '%s' "$args" +# } +# # _username() { # tty=${1:-$(tmux display -p '#{pane_tty}')} # ssh_only=$2 -# # shellcheck disable=SC2039 -# if [ x"$OSTYPE" = x"cygwin" ]; then -# pid=$(ps -a | awk -v tty="${tty##/dev/}" '$5 == tty && /ssh/ && !/vagrant ssh/ && !/autossh/ && !/-W/ { print $1 }') -# [ -n "$pid" ] && ssh_parameters=$(tr '\0' ' ' < "/proc/$pid/cmdline" | sed 's/^ssh //') -# else -# ssh_parameters=$(ps -t "$tty" -o command= | awk '/ssh/ && !/vagrant ssh/ && !/autossh/ && !/-W/ { $1=""; print $0; exit }') -# fi -# if [ -n "$ssh_parameters" ]; then +# +# tty_info=$(_tty_info "$tty") +# command=$(printf '%s' "$tty_info" | cut -d' ' -f3-) +# +# ssh_or_mosh_args=$(_ssh_or_mosh_args "$command") +# if [ -n "$ssh_or_mosh_args" ]; then # # shellcheck disable=SC2086 -# username=$(ssh -G $ssh_parameters 2>/dev/null | awk 'NR > 2 { exit } ; /^user / { print $2 }') +# username=$(ssh -G $ssh_or_mosh_args 2>/dev/null | awk 'NR > 2 { exit } ; /^user / { print $2 }') # # shellcheck disable=SC2086 -# [ -z "$username" ] && username=$(ssh -T -o ControlPath=none -o ProxyCommand="sh -c 'echo %%username%% %r >&2'" $ssh_parameters 2>&1 | awk '/^%username% / { print $2; exit }') +# [ -z "$username" ] && username=$(ssh -T -o ControlPath=none -o ProxyCommand="sh -c 'echo %%username%% %r >&2'" $ssh_or_mosh_args 2>&1 | awk '/^%username% / { print $2; exit }') # else # if ! _is_enabled "$ssh_only"; then -# # shellcheck disable=SC2039 -# if [ x"$OSTYPE" = x"cygwin" ]; then -# username=$(whoami) -# else -# username=$(ps -t "$tty" -o user= -o pid= -o ppid= -o command= | awk ' -# !/ssh/ { user[$2] = $1; ppid[$3] = 1 } -# END { -# for (i in user) -# if (!(i in ppid)) -# { -# print user[i] -# exit -# } -# } -# ') -# fi +# username=$(printf '%s' "$tty_info" | cut -d' ' -f2) # fi # fi # -# echo "$username" +# printf '%s' "$username" # } # # _hostname() { # tty=${1:-$(tmux display -p '#{pane_tty}')} # ssh_only=$2 -# # shellcheck disable=SC2039 -# if [ x"$OSTYPE" = x"cygwin" ]; then -# pid=$(ps -a | awk -v tty="${tty##/dev/}" '$5 == tty && /ssh/ && !/vagrant ssh/ && !/autossh/ && !/-W/ { print $1 }') -# [ -n "$pid" ] && ssh_parameters=$(tr '\0' ' ' < "/proc/$pid/cmdline" | sed 's/^ssh //') -# else -# ssh_parameters=$(ps -t "$tty" -o command= | awk '/ssh/ && !/vagrant ssh/ && !/autossh/ && !/-W/ { $1=""; print $0; exit }') -# fi -# if [ -n "$ssh_parameters" ]; then +# +# tty_info=$(_tty_info "$tty") +# command=$(printf '%s' "$tty_info" | cut -d' ' -f3-) +# +# ssh_or_mosh_args=$(_ssh_or_mosh_args "$command") +# if [ -n "$ssh_or_mosh_args" ]; then # # shellcheck disable=SC2086 -# hostname=$(ssh -G $ssh_parameters 2>/dev/null | awk 'NR > 2 { exit } ; /^hostname / { print $2 }') +# hostname=$(ssh -G $ssh_or_mosh_args 2>/dev/null | awk 'NR > 2 { exit } ; /^hostname / { print $2 }') # # shellcheck disable=SC2086 -# [ -z "$hostname" ] && hostname=$(ssh -T -o ControlPath=none -o ProxyCommand="sh -c 'echo %%hostname%% %h >&2'" $ssh_parameters 2>&1 | awk '/^%hostname% / { print $2; exit }') +# [ -z "$hostname" ] && hostname=$(ssh -T -o ControlPath=none -o ProxyCommand="sh -c 'echo %%hostname%% %h >&2'" $ssh_or_mosh_args 2>&1 | awk '/^%hostname% / { print $2; exit }') # #shellcheck disable=SC1004 # hostname=$(echo "$hostname" | awk '\ # { \ @@ -521,7 +583,7 @@ run 'cut -c3- ~/.tmux.conf | sh -s _apply_configuration' # fi # fi # -# echo "$hostname" +# printf '%s' "$hostname" # } # # _root() { @@ -542,6 +604,7 @@ run 'cut -c3- ~/.tmux.conf | sh -s _apply_configuration' # now=$(date +%s) # ;; # *Linux*|*CYGWIN*|*MSYS*|*MINGW*) +# boot=0 # now=$(cut -d' ' -f1 < /proc/uptime) # ;; # *OpenBSD*) @@ -552,12 +615,16 @@ run 'cut -c3- ~/.tmux.conf | sh -s _apply_configuration' # awk -v boot="$boot" -v now="$now" ' # BEGIN { # uptime = now - boot +# y = int(uptime / 31536000) +# dy = int(uptime / 86400) % 365 # d = int(uptime / 86400) # h = int(uptime / 3600) % 24 # m = int(uptime / 60) % 60 # s = int(uptime) % 60 # -# system("tmux set -g @uptime_d " d + 0 " \\; " \ +# system("tmux set -g @uptime_y " y + 0 " \\; " \ +# "set -g @uptime_dy " dy + 0 " \\; " \ +# "set -g @uptime_d " d + 0 " \\; " \ # "set -g @uptime_h " h + 0 " \\; " \ # "set -g @uptime_m " m + 0 " \\; " \ # "set -g @uptime_s " s + 0) @@ -581,19 +648,22 @@ run 'cut -c3- ~/.tmux.conf | sh -s _apply_configuration' # _split_window() { # tty=${1:-$(tmux display -p '#{pane_tty}')} # shift -# # shellcheck disable=SC2039 -# if [ x"$OSTYPE" = x"cygwin" ]; then -# pid=$(ps -a | sort -d | awk -v tty="${tty##/dev/}" '$5 == tty && /ssh/ && !/-W/ { print $1; exit 0 }') -# [ -n "$pid" ] && ssh=$(tr '\0' ' ' < "/proc/$pid/cmdline") -# else -# ssh=$(ps -t "$tty" -o command= | sort -d | awk '/ssh/ && !/-W/ { print $0; exit 0 }') -# fi -# if [ -n "$ssh" ]; then -# # shellcheck disable=SC2046 -# tmux split-window "$@" $(echo "$ssh" | sed -e "s/;/\\\\;/g") -# else -# tmux split-window "$@" -# fi +# +# tty_info=$(_tty_info "$tty") +# command=$(printf '%s' "$tty_info" | cut -d' ' -f3-) +# +# case "$command" in +# *mosh-client*) +# # shellcheck disable=SC2046 +# tmux split-window "$@" mosh $(echo "$command" | sed -E -e 's/.*mosh-client -# (.*)\|.*$/\1/') +# ;; +# *ssh*) +# # shellcheck disable=SC2046 +# tmux split-window "$@" $(echo "$command" | sed -e 's/;/\\;/g') +# ;; +# *) +# tmux split-window "$@" +# esac # } # # _apply_overrides() { @@ -603,7 +673,7 @@ run 'cut -c3- ~/.tmux.conf | sh -s _apply_configuration' # screen-*|tmux-*) # ;; # *) -# tmux set-option -ga terminal-overrides ",$TERM:Tc" +# tmux set-option -ga terminal-overrides ",*256col*:Tc" # ;; # esac # fi @@ -625,7 +695,7 @@ run 'cut -c3- ~/.tmux.conf | sh -s _apply_configuration' # fi # eval "tmux $left $right" 2>/dev/null || true # done << EOF -# $(tmux list-keys 2>/dev/null | grep -e 'new-window\(\s\+-c\s\+"#{pane_current_path}\|$\)') +# $(tmux list-keys 2>/dev/null | grep -E 'new-window(\s+-c\s+"#{pane_current_path}"|$)') # EOF # # tmux_conf_new_pane_retain_current_path=${tmux_conf_new_pane_retain_current_path:-true} @@ -633,13 +703,13 @@ run 'cut -c3- ~/.tmux.conf | sh -s _apply_configuration' # [ -z "$line" ] && continue # left=$(printf '%s' "$line" | cut -c-"$column" | sed -E -e 's/[^ \ta-zA-Z0-9,._+@%/-]/\\&/g') # if _is_enabled "$tmux_conf_new_pane_retain_current_path"; then -# right=$(printf '%s' "$line" | cut -c"$column-" | awk -F'\"' 'BEGIN { OFS = FS } { for (i = 1; i <= NF; i+=2) { gsub(/#{.+}/, "\"&\"", $i) } print }' | sed -E -e 's/split-window([ \t]+-(h|v))?$/& -c "#{pane_current_path}"/g') +# right=$(printf '%s' "$line" | cut -c"$column-" | awk -F'\"' 'BEGIN { OFS = FS } { for (i = 1; i <= NF; i+=2) { gsub(/#{.+}/, "\"&\"", $i) } print }' | sed -E -e '/#\{pane_current_path\}/!s/split(-|_)window([ \t]+#\{pane_tty\})?([ \t]+-(h|v))?/& -c "#{pane_current_path}"/g') # else -# right=$(printf '%s' "$line" | cut -c"$column"- | awk -F'\"' 'BEGIN { OFS = FS } { for (i = 1; i <= NF; i+=2) { gsub(/#{.+}/, "\"&\"", $i) } print }' | sed -E -e 's/-c[ \t]+"#\{pane_current_path\}"$//g') +# right=$(printf '%s' "$line" | cut -c"$column"- | awk -F'\"' 'BEGIN { OFS = FS } { for (i = 1; i <= NF; i+=2) { gsub(/#{.+}/, "\"&\"", $i) } print }' | sed -E -e 's/[ \t]+(-c[ \t]+(\\")?"#\{pane_current_path\}"(\\")?|-c #\{pane_current_path\})//g') # fi # eval "tmux $left $right" 2>/dev/null || true # done << EOF -# $(tmux list-keys 2>/dev/null | grep -e 'split\(-\|_\)window') +# $(tmux list-keys 2>/dev/null | grep -E 'split(-|_)window') # EOF # # tmux_conf_new_pane_reconnect_ssh=${tmux_conf_new_pane_reconnect_ssh:-false} @@ -647,13 +717,13 @@ run 'cut -c3- ~/.tmux.conf | sh -s _apply_configuration' # [ -z "$line" ] && continue # left=$(printf '%s' "$line" | cut -c-"$column" | sed -E -e 's/[^ \ta-zA-Z0-9,._+@%/-]/\\&/g') # if _is_enabled "$tmux_conf_new_pane_reconnect_ssh"; then -# right=$(printf '%s' "$line" | cut -c"$column"- | awk -F'\"' 'BEGIN { OFS = FS } { for (i = 1; i <= NF; i+=2) { gsub(/#{.+}/, "\"&\"", $i) } print }' | sed -E -e 's/split-window([^;]+)/run-shell "cut -c3- ~\/\.tmux\.conf | sh -s _split_window #{pane_tty}\1"/g') +# right=$(printf '%s' "$line" | cut -c"$column"- | awk -F'\"' 'BEGIN { OFS = FS } { for (i = 1; i <= NF; i+=2) { gsub(/#{.+}/, "\"&\"", $i) } print }' | sed -E -e '/_split_window/!s/"/\\"/g' -e 's/split-window([^;]*)/run-shell "cut -c3- ~\/\.tmux\.conf | sh -s _split_window #{pane_tty}\1"/g') # else -# right=$(printf '%s' "$line" | cut -c"$column"- | awk -F'\"' 'BEGIN { OFS = FS } { for (i = 1; i <= NF; i+=2) { gsub(/#{.+}/, "\"&\"", $i) } print }' | sed -E -e 's/run-shell "cut -c3- ~\/\.tmux\.conf \| sh -s _split_window #\{pane_tty\}([^;]+)"/split-window\1/g' -e 's/#\{.+\}/\"&\"/g') +# right=$(printf '%s' "$line" | cut -c"$column"- | awk -F'\"' 'BEGIN { OFS = FS } { for (i = 1; i <= NF; i+=2) { gsub(/#{.+}/, "\"&\"", $i) } print }' | sed -E -e 's/\\"/"/g' -e 's/run-shell "cut -c3- ~\/\.tmux\.conf \| sh -s _split_window #\{pane_tty\}([^;]*)"/split-window\1/g' -e 's/#\{.+\}/\"&\"/g') # fi # eval "tmux $left $right" 2>/dev/null || true # done << EOF -# $(tmux list-keys 2>/dev/null | grep -e 'split\(-\|_\)window') +# $(tmux list-keys 2>/dev/null | grep -E 'split(-|_)window') # EOF # # tmux_conf_new_session_prompt=${tmux_conf_new_session_prompt:-false} @@ -661,13 +731,13 @@ run 'cut -c3- ~/.tmux.conf | sh -s _apply_configuration' # [ -z "$line" ] && continue # left=$(printf '%s' "$line" | cut -c-"$column" | sed -E -e 's/[^ \ta-zA-Z0-9,._+@%/-]/\\&/g') # if _is_enabled "$tmux_conf_new_session_prompt"; then -# right=$(printf '%s' "$line" | cut -c"$column"- | awk -F'\"' 'BEGIN { OFS = FS } { for (i = 1; i <= NF; i+=2) { gsub(/#{.+}/, "\"&\"", $i) } print }' | sed -E -e 's/new-session$/command-prompt -p new-session \"new-session -s %%\"/g') +# right=$(printf '%s' "$line" | cut -c"$column"- | awk -F'\"' 'BEGIN { OFS = FS } { for (i = 1; i <= NF; i+=2) { gsub(/#{.+}/, "\"&\"", $i) } print }' | sed -E -e 's/new-session$/command-prompt -p new-session \"new-session -s '"'"'%%'"'"'\"/g') # else # right=$(printf '%s' "$line" | cut -c"$column"- | awk -F'\"' 'BEGIN { OFS = FS } { for (i = 1; i <= NF; i+=2) { gsub(/#{.+}/, "\"&\"", $i) } print }'| sed -E -e 's/command-prompt -p new-session[^;]+/new-session/g') # fi # eval "tmux $left $right" 2>/dev/null || true # done << EOF -# $(tmux list-keys 2>/dev/null | grep -e 'new-session') +# $(tmux list-keys 2>/dev/null | grep 'new-session') # EOF # # tmux_conf_copy_to_os_clipboard=${tmux_conf_copy_to_os_clipboard:-false} @@ -681,10 +751,10 @@ run 'cut -c3- ~/.tmux.conf | sh -s _apply_configuration' # if [ -n "$command" ]; then # # shellcheck disable=SC2086 # for table in "" "-t emacs-copy" "-t vi-copy"; do -# line=$(tmux list-keys $table 2>/dev/null | grep -e 'copy-selection\|copy-pipe' | head -1) +# line=$(tmux list-keys $table 2>/dev/null | grep -E 'copy-selection|copy-pipe' | head -1) +# [ -z "$line" ] && continue # prefix=${line%copy-*} # column=${#prefix} -# [ -z "$line" ] && continue # # while IFS= read -r line; do # [ -z "$line" ] && continue @@ -692,11 +762,11 @@ run 'cut -c3- ~/.tmux.conf | sh -s _apply_configuration' # if _is_enabled "$tmux_conf_copy_to_os_clipboard"; then # right=$(printf '%s' "$line" | cut -c"$column"- | awk -F'\"' 'BEGIN { OFS = FS } { for (i = 1; i <= NF; i+=2) { gsub(/#{.+}/, "\"&\"", $i) } print }' | sed -E -e "s/copy-selection(-and-cancel)?$/copy-pipe\1 \"$command\"/g") # else -# right=$(printf '%s' "$line" | cut -c"$column"- | awk -F'\"' 'BEGIN { OFS = FS } { for (i = 1; i <= NF; i+=2) { gsub(/#{.+}/, "\"&\"", $i) } print }' | sed -E -e "s/copy-pipe(-and-cancel)? \"$command\"$/copy-selection\1/g") +# right=$(printf '%s' "$line" | cut -c"$column"- | awk -F'\"' 'BEGIN { OFS = FS } { for (i = 1; i <= NF; i+=2) { gsub(/#{.+}/, "\"&\"", $i) } print }' | sed -E -e "s/copy-pipe(-and-cancel)? \"?$command\"?$/copy-selection\1/g") # fi # eval "tmux $left $right" 2>/dev/null || true # done << EOF -# $(tmux list-keys $table 2>/dev/null | grep -e 'copy-selection\|copy-pipe') +# $(tmux list-keys $table 2>/dev/null | grep -E 'copy-selection|copy-pipe') # EOF # done # fi @@ -747,10 +817,10 @@ run 'cut -c3- ~/.tmux.conf | sh -s _apply_configuration' # # # -- status line ------------------------------------------------------- # -# tmux_conf_theme_left_separator_main=${tmux_conf_theme_left_separator_main-''} -# tmux_conf_theme_left_separator_sub=${tmux_conf_theme_left_separator_sub-'|'} -# tmux_conf_theme_right_separator_main=${tmux_conf_theme_right_separator_main-''} -# tmux_conf_theme_right_separator_sub=${tmux_conf_theme_right_separator_sub-'|'} +# tmux_conf_theme_left_separator_main=$(_decode_unicode_escapes "${tmux_conf_theme_left_separator_main-''}") +# tmux_conf_theme_left_separator_sub=$(_decode_unicode_escapes "${tmux_conf_theme_left_separator_sub-'|'}") +# tmux_conf_theme_right_separator_main=$(_decode_unicode_escapes "${tmux_conf_theme_right_separator_main-''}") +# tmux_conf_theme_right_separator_sub=$(_decode_unicode_escapes "${tmux_conf_theme_right_separator_sub-'|'}") # # tmux_conf_theme_message_fg=${tmux_conf_theme_message_fg:-'#000000'} # black # tmux_conf_theme_message_bg=${tmux_conf_theme_message_bg:-'#ffff00'} # yellow @@ -774,6 +844,17 @@ run 'cut -c3- ~/.tmux.conf | sh -s _apply_configuration' # set -g status-left-style "fg=$tmux_conf_theme_status_fg,bg=$tmux_conf_theme_status_bg,$tmux_conf_theme_status_attr" \;\ # set -g status-right-style "fg=$tmux_conf_theme_status_fg,bg=$tmux_conf_theme_status_bg,$tmux_conf_theme_status_attr" # +# tmux_conf_theme_terminal_title=${tmux_conf_theme_terminal_title:-'#h ❐ #S ● #I #W'} +# +# tmux_conf_theme_terminal_title=$(echo "$tmux_conf_theme_terminal_title" | sed \ +# -e 's%#{circled_window_index}%#(cut -c3- ~/.tmux.conf | sh -s _circled #I)%g' \ +# -e 's%#{circled_session_name}%#(cut -c3- ~/.tmux.conf | sh -s _circled #S)%g' \ +# -e 's%#{username}%#(cut -c3- ~/.tmux.conf | sh -s _username #{pane_tty} false #D)%g' \ +# -e 's%#{hostname}%#(cut -c3- ~/.tmux.conf | sh -s _hostname #{pane_tty} false #D)%g' \ +# -e 's%#{username_ssh}%#(cut -c3- ~/.tmux.conf | sh -s _username #{pane_tty} true #D)%g' \ +# -e 's%#{hostname_ssh}%#(cut -c3- ~/.tmux.conf | sh -s _hostname #{pane_tty} true #D)%g') +# tmux set -g set-titles-string "$(_decode_unicode_escapes "$tmux_conf_theme_terminal_title")" +# # tmux_conf_theme_window_status_fg=${tmux_conf_theme_window_status_fg:-'#8a8a8a'} # white # tmux_conf_theme_window_status_bg=${tmux_conf_theme_window_status_bg:-'#080808'} # dark gray # tmux_conf_theme_window_status_attr=${tmux_conf_theme_window_status_attr:-'none'} @@ -784,18 +865,30 @@ run 'cut -c3- ~/.tmux.conf | sh -s _apply_configuration' # tmux_conf_theme_window_status_current_attr=${tmux_conf_theme_window_status_current_attr:-'bold'} # tmux_conf_theme_window_status_current_format=${tmux_conf_theme_window_status_current_format:-'#I #W'} # if [ x"$(tmux show -g -v status-justify)" = x"right" ]; then -# tmux_conf_theme_window_status_current_format="#[fg=$tmux_conf_theme_window_status_current_bg,bg=$tmux_conf_theme_window_status_bg]$tmux_conf_theme_right_separator_main#[fg=default,bg=default,default] $tmux_conf_theme_window_status_current_format #[fg=$tmux_conf_theme_window_status_bg,bg=$tmux_conf_theme_window_status_current_bg,none]$tmux_conf_theme_right_separator_main" +# tmux_conf_theme_window_status_current_format="#[fg=$tmux_conf_theme_window_status_current_bg,bg=$tmux_conf_theme_window_status_bg]$tmux_conf_theme_right_separator_main#[fg=$tmux_conf_theme_window_status_current_fg,bg=$tmux_conf_theme_window_status_current_bg,$tmux_conf_theme_window_status_current_attr] $tmux_conf_theme_window_status_current_format #[fg=$tmux_conf_theme_window_status_bg,bg=$tmux_conf_theme_window_status_current_bg,none]$tmux_conf_theme_right_separator_main" # else -# tmux_conf_theme_window_status_current_format="#[fg=$tmux_conf_theme_window_status_bg,bg=$tmux_conf_theme_window_status_current_bg]$tmux_conf_theme_left_separator_main#[fg=default,bg=default,default] $tmux_conf_theme_window_status_current_format #[fg=$tmux_conf_theme_window_status_current_bg,bg=$tmux_conf_theme_status_bg,none]$tmux_conf_theme_left_separator_main" +# tmux_conf_theme_window_status_current_format="#[fg=$tmux_conf_theme_window_status_bg,bg=$tmux_conf_theme_window_status_current_bg]$tmux_conf_theme_left_separator_main#[fg=$tmux_conf_theme_window_status_current_fg,bg=$tmux_conf_theme_window_status_current_bg,$tmux_conf_theme_window_status_current_attr] $tmux_conf_theme_window_status_current_format #[fg=$tmux_conf_theme_window_status_current_bg,bg=$tmux_conf_theme_status_bg,none]$tmux_conf_theme_left_separator_main" # fi # -# tmux_conf_theme_window_status_format=$(echo "$tmux_conf_theme_window_status_format" | sed 's%#{circled_window_index}%#(cut -c3- ~/.tmux.conf | sh -s _circled_digit #I)%g') -# tmux_conf_theme_window_status_current_format=$(echo "$tmux_conf_theme_window_status_current_format" | sed 's%#{circled_window_index}%#(cut -c3- ~/.tmux.conf | sh -s _circled_digit #I)%g') +# tmux_conf_theme_window_status_format=$(echo "$tmux_conf_theme_window_status_format" | sed \ +# -e 's%#{circled_window_index}%#(cut -c3- ~/.tmux.conf | sh -s _circled #I)%g' \ +# -e 's%#{circled_session_name}%#(cut -c3- ~/.tmux.conf | sh -s _circled #S)%g' \ +# -e 's%#{username}%#(cut -c3- ~/.tmux.conf | sh -s _username #{pane_tty} false #D)%g' \ +# -e 's%#{hostname}%#(cut -c3- ~/.tmux.conf | sh -s _hostname #{pane_tty} false #D)%g' \ +# -e 's%#{username_ssh}%#(cut -c3- ~/.tmux.conf | sh -s _username #{pane_tty} true #D)%g' \ +# -e 's%#{hostname_ssh}%#(cut -c3- ~/.tmux.conf | sh -s _hostname #{pane_tty} true #D)%g') +# tmux_conf_theme_window_status_current_format=$(echo "$tmux_conf_theme_window_status_current_format" | sed \ +# -e 's%#{circled_window_index}%#(cut -c3- ~/.tmux.conf | sh -s _circled #I)%g' \ +# -e 's%#{circled_session_name}%#(cut -c3- ~/.tmux.conf | sh -s _circled #S)%g' \ +# -e 's%#{username}%#(cut -c3- ~/.tmux.conf | sh -s _username #{pane_tty} false #D)%g' \ +# -e 's%#{hostname}%#(cut -c3- ~/.tmux.conf | sh -s _hostname #{pane_tty} false #D)%g' \ +# -e 's%#{username_ssh}%#(cut -c3- ~/.tmux.conf | sh -s _username #{pane_tty} true #D)%g' \ +# -e 's%#{hostname_ssh}%#(cut -c3- ~/.tmux.conf | sh -s _hostname #{pane_tty} true #D)%g') # # tmux setw -g window-status-style "fg=$tmux_conf_theme_window_status_fg,bg=$tmux_conf_theme_window_status_bg,$tmux_conf_theme_window_status_attr" \;\ -# setw -g window-status-format "$tmux_conf_theme_window_status_format" \;\ +# setw -g window-status-format "$(_decode_unicode_escapes "$tmux_conf_theme_window_status_format")" \;\ # setw -g window-status-current-style "fg=$tmux_conf_theme_window_status_current_fg,bg=$tmux_conf_theme_window_status_current_bg,$tmux_conf_theme_window_status_current_attr" \;\ -# setw -g window-status-current-format "$tmux_conf_theme_window_status_current_format" +# setw -g window-status-current-format "$(_decode_unicode_escapes "$tmux_conf_theme_window_status_current_format")" # # tmux_conf_theme_window_status_activity_fg=${tmux_conf_theme_window_status_activity_fg:-'default'} # tmux_conf_theme_window_status_activity_bg=${tmux_conf_theme_window_status_activity_bg:-'default'} @@ -829,6 +922,11 @@ run 'cut -c3- ~/.tmux.conf | sh -s _apply_configuration' # tmux_conf_theme_root_bg=${tmux_conf_theme_root_bg:-'none'} # tmux_conf_theme_root_attr=${tmux_conf_theme_root_attr:-'bold,blink'} # +# tmux_conf_theme_synchronized=${tmux_conf_theme_synchronized:-'🔒'} # U+1F512 +# tmux_conf_theme_synchronized_fg=${tmux_conf_theme_synchronized_fg:-'none'} +# tmux_conf_theme_synchronized_bg=${tmux_conf_theme_synchronized_bg:-'none'} +# tmux_conf_theme_synchronized_attr=${tmux_conf_theme_synchronized_attr:-'none'} +# # # -- status left style # # tmux_conf_theme_status_left=${tmux_conf_theme_status_left-' ❐ #S '} @@ -845,6 +943,9 @@ run 'cut -c3- ~/.tmux.conf | sh -s _apply_configuration' # tmux_conf_theme_status_left=$(echo "$tmux_conf_theme_status_left" | sed \ # -e "s%#{root}%#[fg=$tmux_conf_theme_root_fg]#[bg=$tmux_conf_theme_root_bg]#[$tmux_conf_theme_root_attr]#(cut -c3- ~/.tmux.conf | sh -s _root #{pane_tty} #D)#[inherit]%g") # +# tmux_conf_theme_status_left=$(echo "$tmux_conf_theme_status_left" | sed \ +# -e "s%#{synchronized}%#[fg=$tmux_conf_theme_synchronized_fg]#[bg=$tmux_conf_theme_synchronized_bg]#[$tmux_conf_theme_synchronized_attr]#{?pane_synchronized,$tmux_conf_theme_synchronized,}%g") +# # if [ -n "$tmux_conf_theme_status_left" ]; then # status_left=$(awk \ # -v fg_="$tmux_conf_theme_status_left_fg" \ @@ -929,6 +1030,9 @@ run 'cut -c3- ~/.tmux.conf | sh -s _apply_configuration' # tmux_conf_theme_status_right=$(echo "$tmux_conf_theme_status_right" | sed \ # -e "s%#{root}%#[fg=$tmux_conf_theme_root_fg]#[bg=$tmux_conf_theme_root_bg]#[$tmux_conf_theme_root_attr]#(cut -c3- ~/.tmux.conf | sh -s _root #{pane_tty} #D)#[inherit]%g") # +# tmux_conf_theme_status_right=$(echo "$tmux_conf_theme_status_right" | sed \ +# -e "s%#{synchronized}%#[fg=$tmux_conf_theme_synchronized_fg]#[bg=$tmux_conf_theme_synchronized_bg]#[$tmux_conf_theme_synchronized_attr]#{?pane_synchronized,$tmux_conf_theme_synchronized,}%g") +# # if [ -n "$tmux_conf_theme_status_right" ]; then # status_right=$(awk \ # -v fg_="$tmux_conf_theme_status_right_fg" \ @@ -1017,14 +1121,14 @@ run 'cut -c3- ~/.tmux.conf | sh -s _apply_configuration' # -e 's/#\{(\?)?battery_status/#\{\1@battery_status/g' \ # -e 's/#\{(\?)?battery_percentage/#\{\1@battery_percentage/g') # -# tmux set -g '@battery_bar_symbol_full' "$tmux_conf_battery_bar_symbol_full" \;\ -# set -g '@battery_bar_symbol_empty' "$tmux_conf_battery_bar_symbol_empty" \;\ +# tmux set -g '@battery_bar_symbol_full' "$(_decode_unicode_escapes "$tmux_conf_battery_bar_symbol_full")" \;\ +# set -g '@battery_bar_symbol_empty' "$(_decode_unicode_escapes "$tmux_conf_battery_bar_symbol_empty")" \;\ # set -g '@battery_bar_length' "$tmux_conf_battery_bar_length" \;\ # set -g '@battery_bar_palette' "$tmux_conf_battery_bar_palette" \;\ # set -g '@battery_hbar_palette' "$tmux_conf_battery_hbar_palette" \;\ # set -g '@battery_vbar_palette' "$tmux_conf_battery_vbar_palette" \;\ -# set -g '@battery_status_charging' "$tmux_conf_battery_status_charging" \;\ -# set -g '@battery_status_discharging' "$tmux_conf_battery_status_discharging" +# set -g '@battery_status_charging' "$(_decode_unicode_escapes "$tmux_conf_battery_status_charging")" \;\ +# set -g '@battery_status_discharging' "$(_decode_unicode_escapes "$tmux_conf_battery_status_discharging")" # status_right="#(cut -c3- ~/.tmux.conf | sh -s _battery)$status_right" # ;; # esac @@ -1045,14 +1149,18 @@ run 'cut -c3- ~/.tmux.conf | sh -s _apply_configuration' # esac # # case "$status_left $status_right" in -# *'#{uptime_d}'*|*'#{uptime_h}'*|*'#{uptime_m}'*) +# *'#{uptime_d}'*|*'#{uptime_h}'*|*'#{uptime_m}'*|*'#{uptime_s}'*) # status_left=$(echo "$status_left" | sed -E \ +# -e 's/#\{(\?)?uptime_y/#\{\1@uptime_y/g' \ # -e 's/#\{(\?)?uptime_d/#\{\1@uptime_d/g' \ +# -e '/@uptime_y/ s/@uptime_d/@uptime_dy/g' \ # -e 's/#\{(\?)?uptime_h/#\{\1@uptime_h/g' \ # -e 's/#\{(\?)?uptime_m/#\{\1@uptime_m/g' \ # -e 's/#\{(\?)?uptime_s/#\{\1@uptime_s/g') # status_right=$(echo "$status_right" | sed -E \ +# -e 's/#\{(\?)?uptime_y/#\{\1@uptime_y/g' \ # -e 's/#\{(\?)?uptime_d/#\{\1@uptime_d/g' \ +# -e '/@uptime_y/ s/@uptime_d/@uptime_dy/g' \ # -e 's/#\{(\?)?uptime_h/#\{\1@uptime_h/g' \ # -e 's/#\{(\?)?uptime_m/#\{\1@uptime_m/g' \ # -e 's/#\{(\?)?uptime_s/#\{\1@uptime_s/g') @@ -1070,11 +1178,11 @@ run 'cut -c3- ~/.tmux.conf | sh -s _apply_configuration' # ;; # esac # -# status_left=$(echo "$status_left" | sed 's%#{circled_session_name}%#(cut -c3- ~/.tmux.conf | sh -s _circled_digit #S)%g') -# status_right=$(echo "$status_right" | sed 's%#{circled_session_name}%#(cut -c3- ~/.tmux.conf | sh -s _circled_digit #S)%g') +# status_left=$(echo "$status_left" | sed 's%#{circled_session_name}%#(cut -c3- ~/.tmux.conf | sh -s _circled #S)%g') +# status_right=$(echo "$status_right" | sed 's%#{circled_session_name}%#(cut -c3- ~/.tmux.conf | sh -s _circled #S)%g') # -# tmux set -g status-left-length 1000 \; set -g status-left "$status_left" \;\ -# set -g status-right-length 1000 \; set -g status-right "$status_right" +# tmux set -g status-left-length 1000 \; set -g status-left "$(_decode_unicode_escapes "$status_left")" \;\ +# set -g status-right-length 1000 \; set -g status-right "$(_decode_unicode_escapes "$status_right")" # # # -- clock ------------------------------------------------------------- # @@ -1102,7 +1210,7 @@ run 'cut -c3- ~/.tmux.conf | sh -s _apply_configuration' # _apply_overrides # _apply_bindings # _apply_theme -# for name in $(printenv | grep -Eo '^tmux_conf_[^=]+'); do tmux setenv -gu "$name"; done; +# for name in $(printenv | grep -E -o '^tmux_conf_[^=]+'); do tmux setenv -gu "$name"; done; # } # # _urlview() { @@ -1116,3 +1224,18 @@ run 'cut -c3- ~/.tmux.conf | sh -s _apply_configuration' # } # # "$@" + +# Custom added - MUST be in the end +# List of plugins +set -g @plugin 'tmux-plugins/tpm' +set -g @plugin 'tmux-plugins/tmux-sensible' + +set -g @plugin 'tmux-plugins/tmux-resurrect' +set -g @resurrect-processes 'vi vim nvim man less more tail top htop' + +set -g @plugin 'tmux-plugins/tmux-continuum' + +set -g @continuum-restore 'on' + +# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf) +run -b '~/.tmux/plugins/tpm/tpm' diff --git a/.tmux.conf.local b/.tmux.conf.local index 3e4276d..83d7104 100644 --- a/.tmux.conf.local +++ b/.tmux.conf.local @@ -90,19 +90,39 @@ tmux_conf_theme_status_fg='#8a8a8a' # light gray tmux_conf_theme_status_bg='#080808' # dark gray tmux_conf_theme_status_attr='none' +# terminal title +# - built-in variables are: +# - #{circled_window_index} +# - #{circled_session_name} +# - #{hostname} +# - #{hostname_ssh} +# - #{username} +# - #{username_ssh} +tmux_conf_theme_terminal_title='#h ❐ #S ● #I #W' + # window status style # - built-in variables are: # - #{circled_window_index} +# - #{circled_session_name} +# - #{hostname} +# - #{hostname_ssh} +# - #{username} +# - #{username_ssh} tmux_conf_theme_window_status_fg='#8a8a8a' # light gray tmux_conf_theme_window_status_bg='#080808' # dark gray tmux_conf_theme_window_status_attr='none' tmux_conf_theme_window_status_format='#I #W' #tmux_conf_theme_window_status_format='#{circled_window_index} #W' -# tmux_conf_theme_window_status_format='#I #W#{?window_bell_flag,🔔,}#{?window_zoomed_flag,🔍,}' +#tmux_conf_theme_window_status_format='#I #W#{?window_bell_flag,🔔,}#{?window_zoomed_flag,🔍,}' # window current status style # - built-in variables are: # - #{circled_window_index} +# - #{circled_session_name} +# - #{hostname} +# - #{hostname_ssh} +# - #{username} +# - #{username_ssh} tmux_conf_theme_window_status_current_fg='#000000' # black tmux_conf_theme_window_status_current_bg='#00afff' # light blue tmux_conf_theme_window_status_current_attr='bold' @@ -126,14 +146,14 @@ tmux_conf_theme_window_status_last_bg='default' tmux_conf_theme_window_status_last_attr='none' # status left/right sections separators -tmux_conf_theme_left_separator_main='' -tmux_conf_theme_left_separator_sub='|' -tmux_conf_theme_right_separator_main='' -tmux_conf_theme_right_separator_sub='|' -tmux_conf_theme_left_separator_main='' # /!\ you don't need to install Powerline -tmux_conf_theme_left_separator_sub='' # you only need fonts patched with -tmux_conf_theme_right_separator_main='' # Powerline symbols or the standalone -tmux_conf_theme_right_separator_sub='' # PowerlineSymbols.otf font +# tmux_conf_theme_left_separator_main='' +# tmux_conf_theme_left_separator_sub='|' +# tmux_conf_theme_right_separator_main='' +# tmux_conf_theme_right_separator_sub='|' +tmux_conf_theme_left_separator_main='\uE0B0' # /!\ you don't need to install Powerline +tmux_conf_theme_left_separator_sub='\uE0B1' # you only need fonts patched with +tmux_conf_theme_right_separator_main='\uE0B2' # Powerline symbols or the standalone +tmux_conf_theme_right_separator_sub='\uE0B3' # PowerlineSymbols.otf font, see README.md # status left/right content: # - separate main sections with '|' @@ -151,17 +171,21 @@ tmux_conf_theme_right_separator_sub='' # PowerlineSymbols.otf font # - #{pairing} # - #{prefix} # - #{root} -# - #{uptime_d} +# - #{synchronized} +# - #{uptime_y} +# - #{uptime_d} (modulo 365 when #{uptime_y} is used) # - #{uptime_h} # - #{uptime_m} # - #{uptime_s} # - #{username} # - #{username_ssh} -tmux_conf_theme_status_left=' ❐ #S | ↑#{?uptime_d, #{uptime_d}d,}#{?uptime_h, #{uptime_h}h,}#{?uptime_m, #{uptime_m}m,} ' +tmux_conf_theme_status_left=' ❐ #S | ↑#{?uptime_y, #{uptime_y}y,}#{?uptime_d, #{uptime_d}d,}#{?uptime_h, #{uptime_h}h,}#{?uptime_m, #{uptime_m}m,} ' +# tmux_conf_theme_status_right='#{prefix}#{pairing}#{synchronized} #{?battery_status, #{battery_status},}#{?battery_bar, #{battery_bar},}#{?battery_percentage, #{battery_percentage},} , %R , %d %b | #{username}#{root} | #{hostname} ' tmux_conf_theme_status_right="IP:#(ifconfig $(route -n | sed -n '3p' | awk '{print $8}') | grep 'inet ' | cut -d ' ' -f 10) , \ DNS:#(echo $(cat /etc/resolv.conf | grep 'nameserver [0-9]' | awk '{print $2}')) , \ Gateway:#(echo $(route -n | sed -n '3p' | awk '{print $2}')) #{prefix}#{pairing} #{?battery_status, #{battery_status},}#{?battery_bar, #{battery_bar},}#{?battery_percentage, #{battery_percentage},} , %R , %d %b | #{username}#{root} | #{hostname}" + # status left style tmux_conf_theme_status_left_fg='#000000,#e4e4e4,#e4e4e4' # black, white , white tmux_conf_theme_status_left_bg='#ffff00,#ff00af,#00afff' # yellow, pink, white blue @@ -169,17 +193,17 @@ tmux_conf_theme_status_left_attr='bold,none,none' # status right style tmux_conf_theme_status_right_fg='#8a8a8a,#e4e4e4,#000000' # light gray, white, black -tmux_conf_theme_status_right_bg='#080808,#d70000,#e4e4e4' # white, dark gray, red, white +tmux_conf_theme_status_right_bg='#080808,#d70000,#e4e4e4' # dark gray, red, white tmux_conf_theme_status_right_attr='none,none,bold' # pairing indicator -tmux_conf_theme_pairing='👓' # U+1F453 +tmux_conf_theme_pairing='👓 ' # U+1F453 tmux_conf_theme_pairing_fg='none' tmux_conf_theme_pairing_bg='none' tmux_conf_theme_pairing_attr='none' # prefix indicator -tmux_conf_theme_prefix='⌨' # U+2328 +tmux_conf_theme_prefix='⌨ ' # U+2328 tmux_conf_theme_prefix_fg='none' tmux_conf_theme_prefix_bg='none' tmux_conf_theme_prefix_attr='none' @@ -190,11 +214,17 @@ tmux_conf_theme_root_fg='none' tmux_conf_theme_root_bg='none' tmux_conf_theme_root_attr='bold,blink' +# synchronized indicator +tmux_conf_theme_synchronized='🔒' # U+1F512 +tmux_conf_theme_synchronized_fg='none' +tmux_conf_theme_synchronized_bg='none' +tmux_conf_theme_synchronized_attr='none' + # battery bar symbols -tmux_conf_battery_bar_symbol_full='◼' -tmux_conf_battery_bar_symbol_empty='◻' -#tmux_conf_battery_bar_symbol_full='♥' -#tmux_conf_battery_bar_symbol_empty='·' +# tmux_conf_battery_bar_symbol_full='◼' +# tmux_conf_battery_bar_symbol_empty='◻' +tmux_conf_battery_bar_symbol_full='♥' +tmux_conf_battery_bar_symbol_empty='·' # battery bar length (in number of symbols), possible values are: # - auto @@ -223,17 +253,28 @@ tmux_conf_battery_vbar_palette='gradient' #tmux_conf_battery_vbar_palette='#d70000,#ff5f00,#5fff00' # red, orange, green # symbols used to indicate whether battery is charging or discharging -tmux_conf_battery_status_charging='↑' # U+2191 -tmux_conf_battery_status_discharging='↓' # U+2193 -#tmux_conf_battery_status_charging='⚡ ' # U+26A1 -#tmux_conf_battery_status_charging='🔌 ' # U+1F50C -#tmux_conf_battery_status_discharging='🔋 ' # U+1F50B +# tmux_conf_battery_status_charging='↑' # U+2191 +# tmux_conf_battery_status_discharging='↓' # U+2193 +tmux_conf_battery_status_charging='⚡ ' # U+26A1 +tmux_conf_battery_status_charging='🔌 ' # U+1F50C +tmux_conf_battery_status_discharging='🔋 ' # U+1F50B -# clock style +# clock style (when you hit + t) +# you may want to use %I:%M %p in place of %R in tmux_conf_theme_status_right tmux_conf_theme_clock_colour='#00afff' # light blue tmux_conf_theme_clock_style='24' +# -- clipboard ----------------------------------------------------------------- + +# in copy mode, copying selection also copies to the OS clipboard +# - true +# - false (default) +# on macOS, this requires installing reattach-to-user-namespace, see README.md +# on Linux, this requires xsel or xclip +tmux_conf_copy_to_os_clipboard=false + + # -- user customizations ------------------------------------------------------- # this is the place to override or undo settings @@ -241,19 +282,19 @@ tmux_conf_theme_clock_style='24' #set -g history-limit 10000 # start with mouse mode enabled -set -g mouse on -# set -g mouse off +#set -g mouse on # force Vi mode # really you should export VISUAL or EDITOR environment variable, see manual -#set -g status-keys vi -#set -g mode-keys vi -set-window-option -g mode-keys vi +set -g status-keys vi +set -g mode-keys vi -# replace C-b by Alt-a (M-a) instead of using both prefixes -set -gu prefix2 -unbind C-a -unbind C-b +# replace C-b by C-a instead of using both prefixes +# set -gu prefix2 +# unbind C-a +# unbind C-b +# set -g prefix C-a +# bind C-a send-prefix set -g prefix M-x bind M-x send-prefix @@ -261,7 +302,7 @@ bind M-x send-prefix #set -g status-position top bind \ split-window -h -c "#{pane_current_path}" # Split panes horizontal -bind - split-window -v -c "#{pane_current_path}" # Split panes vertically + # Use Alt-vim keys without prefix key to switch panes bind -n M-h select-pane -L bind -n M-j select-pane -D @@ -280,10 +321,8 @@ bind k resize-pane -U 5 bind l resize-pane -R 5 bind h resize-pane -L 5 -run-shell /home/viktor/.tmux/resurrect/resurrect.tmux - - # Copy to system clipboard using xlip bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel 'xclip -in -selection clipboard' bind -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel 'xclip -in -selection clipboard' +bind-key s set-window-option synchronize-panes\; display-message "synchronize-panes is now #{?pane_synchronized,on,off}" diff --git a/.vimrc b/.vimrc index 9cb3f76..7dd67c1 100644 --- a/.vimrc +++ b/.vimrc @@ -63,12 +63,6 @@ let g:xptemplate_key = '' "inoremap -" Python main method snippet -"let g:xptemplate_brace_complete = '([{<' -let g:xptemplate_minimal_prefix = 1 -" let g:xptemplate_vars="$author=viktor.barzin" -" let g:xptemplate_vars="$email=viktor.barzin@samitor.com" - " Rebind key " I like to have it here becuase it is easier to reach than the default and " it is next to ``m`` and ``n`` which I use for navigating between tabs. @@ -126,6 +120,7 @@ let g:airline#extensions#tabline#left_alt_sep = '|' let g:airline_powerline_fonts=1 " let g:airline_section_b = '%{strftime("%c")}' " let g:airline_section_y = 'BN: %{bufnr("%")} FT: %y' +let g:airline#extensions#ale#enabled = 1 " Enable wildmenu which is an enhanced command completion " @@ -223,7 +218,7 @@ syntax on vnoremap // y/" " Showing line numbers and length -" set tw=79 " width of document (used by gd) +set tw=79 " width of document (used by gd) " set tw=120 " width of document (used by gd) set nowrap " don't automatically wrap on load set fo-=t " don't automatically wrap text when typing @@ -437,3 +432,22 @@ nnoremap :GundoToggle augroup encrypted autocmd BufNewFile */soton/*/coursework* :X augroup END + +" SEttings for Go +let g:neocomplete#enable_at_startup = 1 " DO NOT MOVE in another file +let g:xptemplate_key = '' + +let g:ale_fixers = { +\ '*': ['remove_trailing_lines', 'trim_whitespace'], +\ 'javascript': ['eslint'], +\} + + +" Put these lines at the very end of your vimrc file. + +" Load all plugins now. +" Plugins need to be added to runtimepath before helptags can be generated. +packloadall +" Load all of the helptags now, after plugins have been loaded. +" All messages and errors will be ignored. +silent! helptags ALL diff --git a/.zshenv b/.zshenv deleted file mode 100644 index eb505b8..0000000 --- a/.zshenv +++ /dev/null @@ -1,15 +0,0 @@ -# export PYENV_ROOT="$HOME/.pyenv" -# export PATH="$PYENV_ROOT/bin:$PATH" -# eval "$(pyenv init -)" - -#export PATH="/home/viktor/.pyenv/bin:$PATH" -#eval "$(pyenv init -)" -#eval "$(pyenv virtualenv-init -)" - - -export VIRTUALENVWRAPPER_PYTHON=python3 -export VIRTUALENV_PYTHON=python3 -export WORKON_HOME=$HOME/.virtualenvs -# export VIRTUALENV_PYTHON=python - -source /home/viktor/.virtualenvwrapper.sh diff --git a/.zshrc b/.zshrc index 3d09131..6d46013 100644 --- a/.zshrc +++ b/.zshrc @@ -118,7 +118,8 @@ j () { # source /usr/local/bin/virtualenvwrapper.sh # eval ssh-agent > /dev/null -VIRTUALENVWRAPPER_PYTHON=python3 +# VIRTUALENVWRAPPER_PYTHON=python3 +export PYTHONBREAKPOINT=ipdb.set_trace source ~/.zshenv # Color man pages @@ -142,3 +143,16 @@ bindkey '^x^e' edit-command-line # Vi style: # zle -N edit-command-line # bindkey -M vicmd v edit-command-line + +# add GO to path +export PATH="/home/viktor/go/bin:$PATH" + +# add JDK 12 go path +export PATH="/opt/jdk-12.0.1/bin:$PATH" + +# add azure core tools to path +export PATH="/opt/azure/:$PATH" + +# add k8s autocompletion +# source <(kubectl completion zsh) +unset command_not_found_handle diff --git a/virtualenvwrapper.sh b/virtualenvwrapper.sh new file mode 100644 index 0000000..2104cb4 --- /dev/null +++ b/virtualenvwrapper.sh @@ -0,0 +1,1352 @@ +# -*- mode: shell-script -*- +# +# Shell functions to act as wrapper for Ian Bicking's virtualenv +# (http://pypi.python.org/pypi/virtualenv) +# +# +# Copyright Doug Hellmann, All Rights Reserved +# +# Permission to use, copy, modify, and distribute this software and its +# documentation for any purpose and without fee is hereby granted, +# provided that the above copyright notice appear in all copies and that +# both that copyright notice and this permission notice appear in +# supporting documentation, and that the name of Doug Hellmann not be used +# in advertising or publicity pertaining to distribution of the software +# without specific, written prior permission. +# +# DOUG HELLMANN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +# INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO +# EVENT SHALL DOUG HELLMANN BE LIABLE FOR ANY SPECIAL, INDIRECT OR +# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF +# USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +# PERFORMANCE OF THIS SOFTWARE. +# +# +# Project home page: http://www.doughellmann.com/projects/virtualenvwrapper/ +# +# +# Setup: +# +# 1. Create a directory to hold the virtual environments. +# (mkdir $HOME/.virtualenvs). +# 2. Add a line like "export WORKON_HOME=$HOME/.virtualenvs" +# to your .bashrc. +# 3. Add a line like "source /path/to/this/file/virtualenvwrapper.sh" +# to your .bashrc. +# 4. Run: source ~/.bashrc +# 5. Run: workon +# 6. A list of environments, empty, is printed. +# 7. Run: mkvirtualenv temp +# 8. Run: workon +# 9. This time, the "temp" environment is included. +# 10. Run: workon temp +# 11. The virtual environment is activated. +# + +# Locate the global Python where virtualenvwrapper is installed. +if [ "$VIRTUALENVWRAPPER_PYTHON" = "" ] +then + VIRTUALENVWRAPPER_PYTHON="$(command \which python)" +fi + +# Set the name of the virtualenv app to use. +if [ "$VIRTUALENVWRAPPER_VIRTUALENV" = "" ] +then + VIRTUALENVWRAPPER_VIRTUALENV="virtualenv" +fi + +# Set the name of the virtualenv-clone app to use. +if [ "$VIRTUALENVWRAPPER_VIRTUALENV_CLONE" = "" ] +then + VIRTUALENVWRAPPER_VIRTUALENV_CLONE="virtualenv-clone" +fi + +# Define script folder depending on the platorm (Win32/Unix) +VIRTUALENVWRAPPER_ENV_BIN_DIR="bin" +if [ "$OS" = "Windows_NT" ] && ([ "$MSYSTEM" = "MINGW32" ] || [ "$MSYSTEM" = "MINGW64" ]) +then + # Only assign this for msys, cygwin use standard Unix paths + # and its own python installation + VIRTUALENVWRAPPER_ENV_BIN_DIR="Scripts" +fi + +# Let the user override the name of the file that holds the project +# directory name. +if [ "$VIRTUALENVWRAPPER_PROJECT_FILENAME" = "" ] +then + export VIRTUALENVWRAPPER_PROJECT_FILENAME=".project" +fi + +# Let the user tell us they never want to cd to projects +# automatically. +export VIRTUALENVWRAPPER_WORKON_CD=${VIRTUALENVWRAPPER_WORKON_CD:-1} + +# Remember where we are running from. +if [ -z "$VIRTUALENVWRAPPER_SCRIPT" ] +then + if [ -n "$BASH" ] + then + export VIRTUALENVWRAPPER_SCRIPT="$BASH_SOURCE" + elif [ -n "$ZSH_VERSION" ] + then + export VIRTUALENVWRAPPER_SCRIPT="$0" + else + export VIRTUALENVWRAPPER_SCRIPT="${.sh.file}" + fi +fi + +# Portable shell scripting is hard, let's go shopping. +# +# People insist on aliasing commands like 'cd', either with a real +# alias or even a shell function. Under bash and zsh, "builtin" forces +# the use of a command that is part of the shell itself instead of an +# alias, function, or external command, while "command" does something +# similar but allows external commands. Under ksh "builtin" registers +# a new command from a shared library, but "command" will pick up +# existing builtin commands. We need to use a builtin for cd because +# we are trying to change the state of the current shell, so we use +# "builtin" for bash and zsh but "command" under ksh. +function virtualenvwrapper_cd { + if [ -n "$BASH" ] + then + builtin \cd "$@" + elif [ -n "$ZSH_VERSION" ] + then + builtin \cd -q "$@" + else + command \cd "$@" + fi +} + +function virtualenvwrapper_expandpath { + if [ "$1" = "" ]; then + return 1 + else + "$VIRTUALENVWRAPPER_PYTHON" -c "import os,sys; sys.stdout.write(os.path.normpath(os.path.expanduser(os.path.expandvars(\"$1\")))+'\n')" + return 0 + fi +} + +function virtualenvwrapper_absolutepath { + if [ "$1" = "" ]; then + return 1 + else + "$VIRTUALENVWRAPPER_PYTHON" -c "import os,sys; sys.stdout.write(os.path.abspath(\"$1\")+'\n')" + return 0 + fi +} + +function virtualenvwrapper_derive_workon_home { + typeset workon_home_dir="$WORKON_HOME" + + # Make sure there is a default value for WORKON_HOME. + # You can override this setting in your .bashrc. + if [ "$workon_home_dir" = "" ] + then + workon_home_dir="$HOME/.virtualenvs" + fi + + # If the path is relative, prefix it with $HOME + # (note: for compatibility) + if echo "$workon_home_dir" | (unset GREP_OPTIONS; command \grep '^[^/~]' > /dev/null) + then + workon_home_dir="$HOME/$WORKON_HOME" + fi + + # Only call on Python to fix the path if it looks like the + # path might contain stuff to expand. + # (it might be possible to do this in shell, but I don't know a + # cross-shell-safe way of doing it -wolever) + if echo "$workon_home_dir" | (unset GREP_OPTIONS; command \egrep '([\$~]|//)' >/dev/null) + then + # This will normalize the path by: + # - Removing extra slashes (e.g., when TMPDIR ends in a slash) + # - Expanding variables (e.g., $foo) + # - Converting ~s to complete paths (e.g., ~/ to /home/brian/ and ~arthur to /home/arthur) + workon_home_dir="$(virtualenvwrapper_expandpath "$workon_home_dir")" + fi + + echo "$workon_home_dir" + return 0 +} + +# Check if the WORKON_HOME directory exists, +# create it if it does not +# seperate from creating the files in it because this used to just error +# and maybe other things rely on the dir existing before that happens. +function virtualenvwrapper_verify_workon_home { + RC=0 + if [ ! -d "$WORKON_HOME/" ] + then + if [ "$1" != "-q" ] + then + echo "NOTE: Virtual environments directory $WORKON_HOME does not exist. Creating..." 1>&2 + fi + mkdir -p "$WORKON_HOME" + RC=$? + fi + return $RC +} + +#HOOK_VERBOSE_OPTION="-q" + +# Function to wrap mktemp so tests can replace it for error condition +# testing. +function virtualenvwrapper_mktemp { + command \mktemp "$@" +} + +# Expects 1 argument, the suffix for the new file. +function virtualenvwrapper_tempfile { + # Note: the 'X's must come last + typeset suffix=${1:-hook} + typeset file + + file="$(virtualenvwrapper_mktemp -t virtualenvwrapper-$suffix-XXXXXXXXXX)" + touch "$file" + if [ $? -ne 0 ] || [ -z "$file" ] || [ ! -f "$file" ] + then + echo "ERROR: virtualenvwrapper could not create a temporary file name." 1>&2 + return 1 + fi + echo $file + return 0 +} + +# Run the hooks +function virtualenvwrapper_run_hook { + typeset hook_script + typeset result + + hook_script="$(virtualenvwrapper_tempfile ${1}-hook)" || return 1 + + # Use a subshell to run the python interpreter with hook_loader so + # we can change the working directory. This avoids having the + # Python 3 interpreter decide that its "prefix" is the virtualenv + # if we happen to be inside the virtualenv when we start. + ( \ + virtualenvwrapper_cd "$WORKON_HOME" && + "$VIRTUALENVWRAPPER_PYTHON" -m 'virtualenvwrapper.hook_loader' \ + $HOOK_VERBOSE_OPTION --script "$hook_script" "$@" \ + ) + result=$? + + if [ $result -eq 0 ] + then + if [ ! -f "$hook_script" ] + then + echo "ERROR: virtualenvwrapper_run_hook could not find temporary file $hook_script" 1>&2 + command \rm -f "$hook_script" + return 2 + fi + # cat "$hook_script" + source "$hook_script" + elif [ "${1}" = "initialize" ] + then + cat - 1>&2 <&2 + return 1 + fi + if [ ! -e "$exe_path" ] + then + echo "ERROR: Found $1 in path as \"$exe_path\" but that does not exist" >&2 + return 1 + fi + return 0 +} + + +# Verify that virtualenv is installed and visible +function virtualenvwrapper_verify_virtualenv { + virtualenvwrapper_verify_resource $VIRTUALENVWRAPPER_VIRTUALENV +} + + +function virtualenvwrapper_verify_virtualenv_clone { + virtualenvwrapper_verify_resource $VIRTUALENVWRAPPER_VIRTUALENV_CLONE +} + + +# Verify that the requested environment exists +function virtualenvwrapper_verify_workon_environment { + typeset env_name="$1" + if [ ! -d "$WORKON_HOME/$env_name" ] + then + echo "ERROR: Environment '$env_name' does not exist. Create it with 'mkvirtualenv $env_name'." >&2 + return 1 + fi + return 0 +} + +# Verify that the active environment exists +function virtualenvwrapper_verify_active_environment { + if [ ! -n "${VIRTUAL_ENV}" ] || [ ! -d "${VIRTUAL_ENV}" ] + then + echo "ERROR: no virtualenv active, or active virtualenv is missing" >&2 + return 1 + fi + return 0 +} + +# Help text for mkvirtualenv +function virtualenvwrapper_mkvirtualenv_help { + echo "Usage: mkvirtualenv [-a project_path] [-i package] [-r requirements_file] [virtualenv options] env_name" + echo + echo " -a project_path" + echo + echo " Provide a full path to a project directory to associate with" + echo " the new environment." + echo + echo " -i package" + echo + echo " Install a package after the environment is created." + echo " This option may be repeated." + echo + echo " -r requirements_file" + echo + echo " Provide a pip requirements file to install a base set of packages" + echo " into the new environment." + echo; + echo 'virtualenv help:'; + echo; + "$VIRTUALENVWRAPPER_VIRTUALENV" $@; +} + +# Create a new environment, in the WORKON_HOME. +# +# Usage: mkvirtualenv [options] ENVNAME +# (where the options are passed directly to virtualenv) +# +#:help:mkvirtualenv: Create a new virtualenv in $WORKON_HOME +function mkvirtualenv { + typeset -a in_args + typeset -a out_args + typeset -i i + typeset tst + typeset a + typeset envname + typeset requirements + typeset packages + typeset interpreter + typeset project + + in_args=( "$@" ) + + if [ -n "$ZSH_VERSION" ] + then + i=1 + tst="-le" + else + i=0 + tst="-lt" + fi + while [ $i $tst $# ] + do + a="${in_args[$i]}" + # echo "arg $i : $a" + case "$a" in + -a) + i=$(( $i + 1 )) + project="${in_args[$i]}" + if [ ! -d "$project" ] + then + echo "Cannot associate project with $project, it is not a directory" 1>&2 + return 1 + fi + project="$(virtualenvwrapper_absolutepath ${project})";; + -h|--help) + virtualenvwrapper_mkvirtualenv_help $a; + return;; + -i) + i=$(( $i + 1 )); + packages="$packages ${in_args[$i]}";; + -p|--python*) + if echo "$a" | grep -q "=" + then + interpreter="$(echo "$a" | cut -f2 -d=)" + else + i=$(( $i + 1 )) + interpreter="${in_args[$i]}" + fi;; + -r) + i=$(( $i + 1 )); + requirements="${in_args[$i]}"; + requirements="$(virtualenvwrapper_expandpath "$requirements")";; + *) + if [ ${#out_args} -gt 0 ] + then + out_args=( "${out_args[@]-}" "$a" ) + else + out_args=( "$a" ) + fi;; + esac + i=$(( $i + 1 )) + done + + if [ ! -z $interpreter ] + then + out_args=( "--python=$interpreter" ${out_args[@]} ) + fi; + + set -- "${out_args[@]}" + + eval "envname=\$$#" + virtualenvwrapper_verify_workon_home || return 1 + virtualenvwrapper_verify_virtualenv || return 1 + ( + [ -n "$ZSH_VERSION" ] && setopt SH_WORD_SPLIT + virtualenvwrapper_cd "$WORKON_HOME" && + "$VIRTUALENVWRAPPER_VIRTUALENV" $VIRTUALENVWRAPPER_VIRTUALENV_ARGS "$@" && + [ -d "$WORKON_HOME/$envname" ] && \ + virtualenvwrapper_run_hook "pre_mkvirtualenv" "$envname" + ) + typeset RC=$? + [ $RC -ne 0 ] && return $RC + + # If they passed a help option or got an error from virtualenv, + # the environment won't exist. Use that to tell whether + # we should switch to the environment and run the hook. + [ ! -d "$WORKON_HOME/$envname" ] && return 0 + + # If they gave us a project directory, set it up now + # so the activate hooks can find it. + if [ ! -z "$project" ] + then + setvirtualenvproject "$WORKON_HOME/$envname" "$project" + RC=$? + [ $RC -ne 0 ] && return $RC + fi + + # Now activate the new environment + workon "$envname" + + if [ ! -z "$requirements" ] + then + pip install -r "$requirements" + fi + + for a in $packages + do + pip install $a + done + + virtualenvwrapper_run_hook "post_mkvirtualenv" +} + +#:help:rmvirtualenv: Remove a virtualenv +function rmvirtualenv { + virtualenvwrapper_verify_workon_home || return 1 + if [ ${#@} = 0 ] + then + echo "Please specify an enviroment." >&2 + return 1 + fi + + # support to remove several environments + typeset env_name + # Must quote the parameters, as environments could have spaces in their names + for env_name in "$@" + do + echo "Removing $env_name..." + typeset env_dir="$WORKON_HOME/$env_name" + if [ "$VIRTUAL_ENV" = "$env_dir" ] + then + echo "ERROR: You cannot remove the active environment ('$env_name')." >&2 + echo "Either switch to another environment, or run 'deactivate'." >&2 + return 1 + fi + + if [ ! -d "$env_dir" ]; then + echo "Did not find environment $env_dir to remove." >&2 + fi + + # Move out of the current directory to one known to be + # safe, in case we are inside the environment somewhere. + typeset prior_dir="$(pwd)" + virtualenvwrapper_cd "$WORKON_HOME" + + virtualenvwrapper_run_hook "pre_rmvirtualenv" "$env_name" + command \rm -rf "$env_dir" + virtualenvwrapper_run_hook "post_rmvirtualenv" "$env_name" + + # If the directory we used to be in still exists, move back to it. + if [ -d "$prior_dir" ] + then + virtualenvwrapper_cd "$prior_dir" + fi + done +} + +# List the available environments. +function virtualenvwrapper_show_workon_options { + virtualenvwrapper_verify_workon_home || return 1 + # NOTE: DO NOT use ls or cd here because colorized versions spew control + # characters into the output list. + # echo seems a little faster than find, even with -depth 3. + # Note that this is a little tricky, as there may be spaces in the path. + # + # 1. Look for environments by finding the activate scripts. + # Use a subshell so we can suppress the message printed + # by zsh if the glob pattern fails to match any files. + # This yields a single, space-separated line containing all matches. + # 2. Replace the trailing newline with a space, so every + # possible env has a space following it. + # 3. Strip the bindir/activate script suffix, replacing it with + # a slash, as that is an illegal character in a directory name. + # This yields a slash-separated list of possible env names. + # 4. Replace each slash with a newline to show the output one name per line. + # 5. Eliminate any lines with * on them because that means there + # were no envs. + (virtualenvwrapper_cd "$WORKON_HOME" && echo */$VIRTUALENVWRAPPER_ENV_BIN_DIR/activate) 2>/dev/null \ + | command \tr "\n" " " \ + | command \sed "s|/$VIRTUALENVWRAPPER_ENV_BIN_DIR/activate |/|g" \ + | command \tr "/" "\n" \ + | command \sed "/^\s*$/d" \ + | (unset GREP_OPTIONS; command \egrep -v '^\*$') 2>/dev/null +} + +function _lsvirtualenv_usage { + echo "lsvirtualenv [-blh]" + echo " -b -- brief mode" + echo " -l -- long mode" + echo " -h -- this help message" +} + +#:help:lsvirtualenv: list virtualenvs +function lsvirtualenv { + + typeset long_mode=true + if command -v "getopts" &> /dev/null + then + # Use getopts when possible + OPTIND=1 + while getopts ":blh" opt "$@" + do + case "$opt" in + l) long_mode=true;; + b) long_mode=false;; + h) _lsvirtualenv_usage; + return 1;; + ?) echo "Invalid option: -$OPTARG" >&2; + _lsvirtualenv_usage; + return 1;; + esac + done + else + # fallback on getopt for other shell + typeset -a args + args=($(getopt blh "$@")) + if [ $? != 0 ] + then + _lsvirtualenv_usage + return 1 + fi + for opt in $args + do + case "$opt" in + -l) long_mode=true;; + -b) long_mode=false;; + -h) _lsvirtualenv_usage; + return 1;; + esac + done + fi + + if $long_mode + then + allvirtualenv showvirtualenv "$env_name" + else + virtualenvwrapper_show_workon_options + fi +} + +#:help:showvirtualenv: show details of a single virtualenv +function showvirtualenv { + typeset env_name="$1" + if [ -z "$env_name" ] + then + if [ -z "$VIRTUAL_ENV" ] + then + echo "showvirtualenv [env]" + return 1 + fi + env_name=$(basename "$VIRTUAL_ENV") + fi + + virtualenvwrapper_run_hook "get_env_details" "$env_name" + echo +} + +# Show help for workon +function virtualenvwrapper_workon_help { + echo "Usage: workon env_name" + echo "" + echo " Deactivate any currently activated virtualenv" + echo " and activate the named environment, triggering" + echo " any hooks in the process." + echo "" + echo " workon" + echo "" + echo " Print a list of available environments." + echo " (See also lsvirtualenv -b)" + echo "" + echo " workon (-h|--help)" + echo "" + echo " Show this help message." + echo "" + echo " workon (-c|--cd) envname" + echo "" + echo " After activating the environment, cd to the associated" + echo " project directory if it is set." + echo "" + echo " workon (-n|--no-cd) envname" + echo "" + echo " After activating the environment, do not cd to the" + echo " associated project directory." + echo "" +} + +#:help:workon: list or change working virtualenvs +function workon { + typeset -a in_args + typeset -a out_args + + in_args=( "$@" ) + + if [ -n "$ZSH_VERSION" ] + then + i=1 + tst="-le" + else + i=0 + tst="-lt" + fi + typeset cd_after_activate=$VIRTUALENVWRAPPER_WORKON_CD + while [ $i $tst $# ] + do + a="${in_args[$i]}" + case "$a" in + -h|--help) + virtualenvwrapper_workon_help; + return 0;; + -n|--no-cd) + cd_after_activate=0;; + -c|--cd) + cd_after_activate=1;; + *) + if [ ${#out_args} -gt 0 ] + then + out_args=( "${out_args[@]-}" "$a" ) + else + out_args=( "$a" ) + fi;; + esac + i=$(( $i + 1 )) + done + + set -- "${out_args[@]}" + + typeset env_name="$1" + if [ "$env_name" = "" ] + then + lsvirtualenv -b + return 1 + elif [ "$env_name" = "." ] + then + # The IFS default of breaking on whitespace causes issues if there + # are spaces in the env_name, so change it. + IFS='%' + env_name="$(basename $(pwd))" + unset IFS + fi + + virtualenvwrapper_verify_workon_home || return 1 + virtualenvwrapper_verify_workon_environment "$env_name" || return 1 + + activate="$WORKON_HOME/$env_name/$VIRTUALENVWRAPPER_ENV_BIN_DIR/activate" + if [ ! -f "$activate" ] + then + echo "ERROR: Environment '$WORKON_HOME/$env_name' does not contain an activate script." >&2 + return 1 + fi + + # Deactivate any current environment "destructively" + # before switching so we use our override function, + # if it exists. + type deactivate >/dev/null 2>&1 + if [ $? -eq 0 ] + then + deactivate + unset -f deactivate >/dev/null 2>&1 + fi + + virtualenvwrapper_run_hook "pre_activate" "$env_name" + + source "$activate" + + # Save the deactivate function from virtualenv under a different name + virtualenvwrapper_original_deactivate=`typeset -f deactivate | sed 's/deactivate/virtualenv_deactivate/g'` + eval "$virtualenvwrapper_original_deactivate" + unset -f deactivate >/dev/null 2>&1 + + # Replace the deactivate() function with a wrapper. + eval 'deactivate () { + typeset env_postdeactivate_hook + typeset old_env + + # Call the local hook before the global so we can undo + # any settings made by the local postactivate first. + virtualenvwrapper_run_hook "pre_deactivate" + + env_postdeactivate_hook="$VIRTUAL_ENV/$VIRTUALENVWRAPPER_ENV_BIN_DIR/postdeactivate" + old_env=$(basename "$VIRTUAL_ENV") + + # Call the original function. + virtualenv_deactivate $1 + + virtualenvwrapper_run_hook "post_deactivate" "$old_env" + + if [ ! "$1" = "nondestructive" ] + then + # Remove this function + unset -f virtualenv_deactivate >/dev/null 2>&1 + unset -f deactivate >/dev/null 2>&1 + fi + + }' + + VIRTUALENVWRAPPER_PROJECT_CD=$cd_after_activate virtualenvwrapper_run_hook "post_activate" + + return 0 +} + + +# Prints the Python version string for the current interpreter. +function virtualenvwrapper_get_python_version { + # Uses the Python from the virtualenv rather than + # VIRTUALENVWRAPPER_PYTHON because we're trying to determine the + # version installed there so we can build up the path to the + # site-packages directory. + "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_ENV_BIN_DIR/python" -V 2>&1 | cut -f2 -d' ' | cut -f-2 -d. +} + +# Prints the path to the site-packages directory for the current environment. +function virtualenvwrapper_get_site_packages_dir { + "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_ENV_BIN_DIR/python" -c "import distutils; print(distutils.sysconfig.get_python_lib())" +} + +# Path management for packages outside of the virtual env. +# Based on a contribution from James Bennett and Jannis Leidel. +# +# add2virtualenv directory1 directory2 ... +# +# Adds the specified directories to the Python path for the +# currently-active virtualenv. This will be done by placing the +# directory names in a path file named +# "virtualenv_path_extensions.pth" inside the virtualenv's +# site-packages directory; if this file does not exist, it will be +# created first. +# +#:help:add2virtualenv: add directory to the import path +function add2virtualenv { + virtualenvwrapper_verify_workon_home || return 1 + virtualenvwrapper_verify_active_environment || return 1 + + site_packages="`virtualenvwrapper_get_site_packages_dir`" + + if [ ! -d "${site_packages}" ] + then + echo "ERROR: currently-active virtualenv does not appear to have a site-packages directory" >&2 + return 1 + fi + + # Prefix with _ to ensure we are loaded as early as possible, + # and at least before easy_install.pth. + path_file="$site_packages/_virtualenv_path_extensions.pth" + + if [ "$*" = "" ] + then + echo "Usage: add2virtualenv dir [dir ...]" + if [ -f "$path_file" ] + then + echo + echo "Existing paths:" + cat "$path_file" | grep -v "^import" + fi + return 1 + fi + + remove=0 + if [ "$1" = "-d" ] + then + remove=1 + shift + fi + + if [ ! -f "$path_file" ] + then + echo "import sys; sys.__plen = len(sys.path)" > "$path_file" || return 1 + echo "import sys; new=sys.path[sys.__plen:]; del sys.path[sys.__plen:]; p=getattr(sys,'__egginsert',0); sys.path[p:p]=new; sys.__egginsert = p+len(new)" >> "$path_file" || return 1 + fi + + for pydir in "$@" + do + absolute_path="$(virtualenvwrapper_absolutepath "$pydir")" + if [ "$absolute_path" != "$pydir" ] + then + echo "Warning: Converting \"$pydir\" to \"$absolute_path\"" 1>&2 + fi + + if [ $remove -eq 1 ] + then + sed -i.tmp "\:^$absolute_path$: d" "$path_file" + else + sed -i.tmp '1 a\ +'"$absolute_path"' +' "$path_file" + fi + rm -f "${path_file}.tmp" + done + return 0 +} + +# Does a ``cd`` to the site-packages directory of the currently-active +# virtualenv. +#:help:cdsitepackages: change to the site-packages directory +function cdsitepackages { + virtualenvwrapper_verify_workon_home || return 1 + virtualenvwrapper_verify_active_environment || return 1 + typeset site_packages="`virtualenvwrapper_get_site_packages_dir`" + virtualenvwrapper_cd "$site_packages/$1" +} + +# Does a ``cd`` to the root of the currently-active virtualenv. +#:help:cdvirtualenv: change to the $VIRTUAL_ENV directory +function cdvirtualenv { + virtualenvwrapper_verify_workon_home || return 1 + virtualenvwrapper_verify_active_environment || return 1 + virtualenvwrapper_cd "$VIRTUAL_ENV/$1" +} + +# Shows the content of the site-packages directory of the currently-active +# virtualenv +#:help:lssitepackages: list contents of the site-packages directory +function lssitepackages { + virtualenvwrapper_verify_workon_home || return 1 + virtualenvwrapper_verify_active_environment || return 1 + typeset site_packages="`virtualenvwrapper_get_site_packages_dir`" + ls $@ "$site_packages" + + path_file="$site_packages/_virtualenv_path_extensions.pth" + if [ -f "$path_file" ] + then + echo + echo "_virtualenv_path_extensions.pth:" + cat "$path_file" + fi +} + +# Toggles the currently-active virtualenv between having and not having +# access to the global site-packages. +#:help:toggleglobalsitepackages: turn access to global site-packages on/off +function toggleglobalsitepackages { + virtualenvwrapper_verify_workon_home || return 1 + virtualenvwrapper_verify_active_environment || return 1 + typeset no_global_site_packages_file="`virtualenvwrapper_get_site_packages_dir`/../no-global-site-packages.txt" + if [ -f $no_global_site_packages_file ]; then + rm $no_global_site_packages_file + [ "$1" = "-q" ] || echo "Enabled global site-packages" + else + touch $no_global_site_packages_file + [ "$1" = "-q" ] || echo "Disabled global site-packages" + fi +} + +#:help:cpvirtualenv: duplicate the named virtualenv to make a new one +function cpvirtualenv { + virtualenvwrapper_verify_workon_home || return 1 + virtualenvwrapper_verify_virtualenv_clone || return 1 + + typeset src_name="$1" + typeset trg_name="$2" + typeset src + typeset trg + + # without a source there is nothing to do + if [ "$src_name" = "" ]; then + echo "Please provide a valid virtualenv to copy." + return 1 + else + # see if it's already in workon + if [ ! -e "$WORKON_HOME/$src_name" ]; then + # so it's a virtualenv we are importing + # make sure we have a full path + # and get the name + src="$(virtualenvwrapper_expandpath "$src_name")" + # final verification + if [ ! -e "$src" ]; then + echo "Please provide a valid virtualenv to copy." + return 1 + fi + src_name="$(basename "$src")" + else + src="$WORKON_HOME/$src_name" + fi + fi + + if [ "$trg_name" = "" ]; then + # target not given, assume + # same as source + trg="$WORKON_HOME/$src_name" + trg_name="$src_name" + else + trg="$WORKON_HOME/$trg_name" + fi + trg="$(virtualenvwrapper_expandpath "$trg")" + + # validate trg does not already exist + # catch copying virtualenv in workon home + # to workon home + if [ -e "$trg" ]; then + echo "$trg_name virtualenv already exists." + return 1 + fi + + echo "Copying $src_name as $trg_name..." + ( + [ -n "$ZSH_VERSION" ] && setopt SH_WORD_SPLIT + virtualenvwrapper_cd "$WORKON_HOME" && + "$VIRTUALENVWRAPPER_VIRTUALENV_CLONE" "$src" "$trg" + [ -d "$trg" ] && + virtualenvwrapper_run_hook "pre_cpvirtualenv" "$src" "$trg_name" && + virtualenvwrapper_run_hook "pre_mkvirtualenv" "$trg_name" + ) + typeset RC=$? + [ $RC -ne 0 ] && return $RC + + [ ! -d "$WORKON_HOME/$trg_name" ] && return 1 + + # Now activate the new environment + workon "$trg_name" + + virtualenvwrapper_run_hook "post_mkvirtualenv" + virtualenvwrapper_run_hook "post_cpvirtualenv" +} + +# +# virtualenvwrapper project functions +# + +# Verify that the PROJECT_HOME directory exists +function virtualenvwrapper_verify_project_home { + if [ -z "$PROJECT_HOME" ] + then + echo "ERROR: Set the PROJECT_HOME shell variable to the name of the directory where projects should be created." >&2 + return 1 + fi + if [ ! -d "$PROJECT_HOME" ] + then + [ "$1" != "-q" ] && echo "ERROR: Project directory '$PROJECT_HOME' does not exist. Create it or set PROJECT_HOME to an existing directory." >&2 + return 1 + fi + return 0 +} + +# Given a virtualenv directory and a project directory, +# set the virtualenv up to be associated with the +# project +#:help:setvirtualenvproject: associate a project directory with a virtualenv +function setvirtualenvproject { + typeset venv="$1" + typeset prj="$2" + if [ -z "$venv" ] + then + venv="$VIRTUAL_ENV" + fi + if [ -z "$prj" ] + then + prj="$(pwd)" + else + prj=$(virtualenvwrapper_absolutepath "${prj}") + fi + + # If what we were given isn't a directory, see if it is under + # $WORKON_HOME. + if [ ! -d "$venv" ] + then + venv="$WORKON_HOME/$venv" + fi + if [ ! -d "$venv" ] + then + echo "No virtualenv $(basename $venv)" 1>&2 + return 1 + fi + + # Make sure we have a valid project setting + if [ ! -d "$prj" ] + then + echo "Cannot associate virtualenv with \"$prj\", it is not a directory" 1>&2 + return 1 + fi + + echo "Setting project for $(basename $venv) to $prj" + echo "$prj" > "$venv/$VIRTUALENVWRAPPER_PROJECT_FILENAME" +} + +# Show help for mkproject +function virtualenvwrapper_mkproject_help { + echo "Usage: mkproject [-f|--force] [-t template] [virtualenv options] project_name" + echo + echo "-f, --force Create the virtualenv even if the project directory" + echo " already exists" + echo + echo "Multiple templates may be selected. They are applied in the order" + echo "specified on the command line." + echo + echo "mkvirtualenv help:" + echo + mkvirtualenv -h + echo + echo "Available project templates:" + echo + "$VIRTUALENVWRAPPER_PYTHON" -c 'from virtualenvwrapper.hook_loader import main; main()' -l project.template +} + +#:help:mkproject: create a new project directory and its associated virtualenv +function mkproject { + typeset -a in_args + typeset -a out_args + typeset -i i + typeset tst + typeset a + typeset t + typeset force + typeset templates + + in_args=( "$@" ) + force=0 + + if [ -n "$ZSH_VERSION" ] + then + i=1 + tst="-le" + else + i=0 + tst="-lt" + fi + while [ $i $tst $# ] + do + a="${in_args[$i]}" + case "$a" in + -h|--help) + virtualenvwrapper_mkproject_help; + return;; + -f|--force) + force=1;; + -t) + i=$(( $i + 1 )); + templates="$templates ${in_args[$i]}";; + *) + if [ ${#out_args} -gt 0 ] + then + out_args=( "${out_args[@]-}" "$a" ) + else + out_args=( "$a" ) + fi;; + esac + i=$(( $i + 1 )) + done + + set -- "${out_args[@]}" + + # echo "templates $templates" + # echo "remainder $@" + # return 0 + + eval "typeset envname=\$$#" + virtualenvwrapper_verify_project_home || return 1 + + if [ -d "$PROJECT_HOME/$envname" -a $force -eq 0 ] + then + echo "Project $envname already exists." >&2 + return 1 + fi + + mkvirtualenv "$@" || return 1 + + virtualenvwrapper_cd "$PROJECT_HOME" + + virtualenvwrapper_run_hook "project.pre_mkproject" $envname + + echo "Creating $PROJECT_HOME/$envname" + mkdir -p "$PROJECT_HOME/$envname" + setvirtualenvproject "$VIRTUAL_ENV" "$PROJECT_HOME/$envname" + + virtualenvwrapper_cd "$PROJECT_HOME/$envname" + + for t in $templates + do + echo + echo "Applying template $t" + # For some reason zsh insists on prefixing the template + # names with a space, so strip them out before passing + # the value to the hook loader. + virtualenvwrapper_run_hook --name $(echo $t | sed 's/^ //') "project.template" "$envname" "$PROJECT_HOME/$envname" + done + + virtualenvwrapper_run_hook "project.post_mkproject" +} + +#:help:cdproject: change directory to the active project +function cdproject { + virtualenvwrapper_verify_workon_home || return 1 + virtualenvwrapper_verify_active_environment || return 1 + if [ -f "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_PROJECT_FILENAME" ] + then + typeset project_dir="$(cat "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_PROJECT_FILENAME")" + if [ ! -z "$project_dir" ] + then + virtualenvwrapper_cd "$project_dir" + else + echo "Project directory $project_dir does not exist" 1>&2 + return 1 + fi + else + echo "No project set in $VIRTUAL_ENV/$VIRTUALENVWRAPPER_PROJECT_FILENAME" 1>&2 + return 1 + fi + return 0 +} + +# +# Temporary virtualenv +# +# Originally part of virtualenvwrapper.tmpenv plugin +# +#:help:mktmpenv: create a temporary virtualenv +function mktmpenv { + typeset tmpenvname + typeset RC + typeset -a in_args + typeset -a out_args + + in_args=( "$@" ) + + if [ -n "$ZSH_VERSION" ] + then + i=1 + tst="-le" + else + i=0 + tst="-lt" + fi + typeset cd_after_activate=$VIRTUALENVWRAPPER_WORKON_CD + while [ $i $tst $# ] + do + a="${in_args[$i]}" + case "$a" in + -n|--no-cd) + cd_after_activate=0;; + -c|--cd) + cd_after_activate=1;; + *) + if [ ${#out_args} -gt 0 ] + then + out_args=( "${out_args[@]-}" "$a" ) + else + out_args=( "$a" ) + fi;; + esac + i=$(( $i + 1 )) + done + + set -- "${out_args[@]}" + + # Generate a unique temporary name + tmpenvname=$("$VIRTUALENVWRAPPER_PYTHON" -c 'import uuid,sys; sys.stdout.write(uuid.uuid4()+"\n")' 2>/dev/null) + if [ -z "$tmpenvname" ] + then + # This python does not support uuid + tmpenvname=$("$VIRTUALENVWRAPPER_PYTHON" -c 'import random,sys; sys.stdout.write(hex(random.getrandbits(64))[2:-1]+"\n")' 2>/dev/null) + fi + tmpenvname="tmp-$tmpenvname" + + # Create the environment + mkvirtualenv "$@" "$tmpenvname" + RC=$? + if [ $RC -ne 0 ] + then + return $RC + fi + + # Change working directory + [ "$cd_after_activate" = "1" ] && cdvirtualenv + + # Create the tmpenv marker file + echo "This is a temporary environment. It will be deleted when you run 'deactivate'." | tee "$VIRTUAL_ENV/README.tmpenv" + + # Update the postdeactivate script + cat - >> "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_ENV_BIN_DIR/postdeactivate" < "$req_file" + if [ -n "$(cat "$req_file")" ] + then + echo "Uninstalling packages:" + cat "$req_file" + echo + pip uninstall -y $(cat "$req_file" | grep -v '^-f' | sed 's/>/=/g' | cut -f1 -d=) + else + echo "Nothing to remove." + fi + rm -f "$req_file" +} + +# +# Run a command in each virtualenv +# +#:help:allvirtualenv: run a command in all virtualenvs +function allvirtualenv { + virtualenvwrapper_verify_workon_home || return 1 + typeset d + + # The IFS default of breaking on whitespace causes issues if there + # are spaces in the env_name, so change it. + IFS='%' + virtualenvwrapper_show_workon_options | while read d + do + [ ! -d "$WORKON_HOME/$d" ] && continue + echo "$d" + echo "$d" | sed 's/./=/g' + # Activate the environment, but not with workon + # because we don't want to trigger any hooks. + (source "$WORKON_HOME/$d/$VIRTUALENVWRAPPER_ENV_BIN_DIR/activate"; + virtualenvwrapper_cd "$VIRTUAL_ENV"; + "$@") + echo + done + unset IFS +} + +#:help:virtualenvwrapper: show this help message +function virtualenvwrapper { + cat <