From 4e720dfb9f59dc3cc35151a12117a393f83df7f5 Mon Sep 17 00:00:00 2001 From: accel Date: Wed, 10 Nov 2021 17:41:19 +0300 Subject: [PATCH] migrate --- global.funcs.zsh | 137 +++++++++++ .../battery-status/battery-status.plugin.zsh | 190 +++++++++++++++ .../battery-status.plugin.zsh.save | 171 +++++++++++++ oh-my-zsh/plugins/gentoo/gentoo.plugin.zsh | 60 +++++ .../plugins/mpvanime/mpvanime.plugin.zsh | 6 + .../portage-edit/portage-edit.plugin.zsh | 0 .../prompt-automatic-refresh.plugin.zsh | 2 + oh-my-zsh/plugins/ssh-agent/README.md | 38 +++ .../plugins/ssh-agent/ssh-agent.plugin.zsh | 42 ++++ oh-my-zsh/plugins/tmux/tmux.extra.conf | 2 + oh-my-zsh/plugins/tmux/tmux.only.conf | 1 + oh-my-zsh/plugins/tmux/tmux.plugin.zsh | 112 +++++++++ zbootstrap.zsh | 14 ++ zssh.funcs.zsh | 227 ++++++++++++++++++ 14 files changed, 1002 insertions(+) create mode 100644 global.funcs.zsh create mode 100644 oh-my-zsh/plugins/battery-status/battery-status.plugin.zsh create mode 100644 oh-my-zsh/plugins/battery-status/battery-status.plugin.zsh.save create mode 100644 oh-my-zsh/plugins/gentoo/gentoo.plugin.zsh create mode 100755 oh-my-zsh/plugins/mpvanime/mpvanime.plugin.zsh create mode 100644 oh-my-zsh/plugins/portage-edit/portage-edit.plugin.zsh create mode 100644 oh-my-zsh/plugins/prompt-automatic-refresh/prompt-automatic-refresh.plugin.zsh create mode 100644 oh-my-zsh/plugins/ssh-agent/README.md create mode 100644 oh-my-zsh/plugins/ssh-agent/ssh-agent.plugin.zsh create mode 100644 oh-my-zsh/plugins/tmux/tmux.extra.conf create mode 100644 oh-my-zsh/plugins/tmux/tmux.only.conf create mode 100644 oh-my-zsh/plugins/tmux/tmux.plugin.zsh create mode 100644 zbootstrap.zsh create mode 100644 zssh.funcs.zsh diff --git a/global.funcs.zsh b/global.funcs.zsh new file mode 100644 index 0000000..5a9fda5 --- /dev/null +++ b/global.funcs.zsh @@ -0,0 +1,137 @@ +if [[ -z $globaldots_path ]]; then + echo 'functions require $globaldots_path to be set!' +fi + +function global_path_expand() +{ + local bin_base=${globaldots_path}/bin + for pathnew in ${*}; do + if [[ ! ${path[(r)${pathnew}]} ]] ; then + path+=(${bin_base}/${pathnew}); + fi + done; +} + +function global_fpath_expand() +{ + local bin_base=${globaldots_path}/bin + for pathnew in ${*}; do + if [[ ! ${fpath[(r)${pathnew}]} ]] ; then + fpath+=${bin_base}/${pathnew} + fi + done; +} + + +function zconfig_checkload() +{ + typeset -a -g globaldots_configs_loaded + if [[ ! ${globaldots_configs_loaded[(r)${1}]} ]] + then + zbootstrap_message zbootstrap "sourcing config '$1'" + source -- $1 2>&1 >> "${HOME}/.log/z_zbootstrap.log" + globaldots_configs_loaded+=("$1") + zbootstrap_message zbootstrap "end sourcing config '$1'" + else + zbootstrap_message zbootstrap "config '$1' already loaded" + fi +} + +function zconfigs_load() +{ + for configfile in ${*}; do + zconfig_checkload $configfile + done +} + + + +function zconfigs_local_load() +{ + + if [[ ! -a ${HOME}/.config/zsh ]]; then + mkdir -p -m 700 ${HOME}/.config/zsh + cp ${globaldots_path}/config/zsh/zshconfig.example ${HOME}/.config/zsh/local.config.zsh + fi + if [[ ! -d ${HOME}/.config/zsh ]]; then + zconfig_checkload ${HOME}/.config/zsh + else + zconfigs_load ${HOME}/.config/zsh/*.config.zsh; + fi +} + +function zbootstrap_message() +{ + local facility=$1 + shift + echo "$(date -Ins) ${@}" >> "${HOME}/.log/z_$facility.log" +} + +function ztools_ensure() +{ + target=${2} + typ=${1} + if ! test -e ${target} + then + zbootstrap_message ztools_ensure "creating '${target}' ($typ) …" + case $typ in + -d) + mkdir -p ${target} \ + || zbootstrap_message ztools_ensure "unable to create directory '${target}'" \ + && return 2 + ;; + -f) + touch ${target} \ + || zbootstrap_message ztools_ensure "unable to create file '${target}'" \ + && return 2 + esac + zbootstrap_message ztools_ensure "target '${target}' created" + elif test ${typ} ${target} + then + zbootstrap_message ztools_ensure "target '${target}' ($typ) present" + return 0 + else + zbootstrap_message ztools_ensure "target '${target}' already exists and it is not a directory" + return 1 + fi +} + +function zbootstrap_noninteractive() +{ + # ensure log directory + zbootstrap_message zbootstrap "ensure directory '${HOME}/.log/'" + ztools_ensure -d "${HOME}/.log/" + # if ! [[ -d "${HOME}/.log/" ]] + # then + # mkdir "${HOME}/.log/" + # else if [[ -e "${HOME}/.log/" ]] + # then + # zbootstrap_message zbootstrap "zbootstrap logdir '${HOME}/.log/' exist and is not a directory" + # fi + # fi + # loading configs + typeset -a -g globaldots_configs_loaded + typeset -a -g path_extra + typeset -a -g config_extra + zbootstrap_message zbootstrap 'load global config' + zconfig_checkload ${globaldots_path}/config/zsh/global.config.zsh + zbootstrap_message zbootstrap 'load local configs' + zconfigs_local_load + for zconfig in $config_extra; do + zbootstrap_message zbootstrap 'load config extra $zconfig' + zconfig_checkload ${globaldots_path}/config/zsh/${zconfig}.config.zsh + done + # expanding settings + zbootstrap_message zbootstrap "expanding path with '$path_extra'" + global_path_expand $path_extra + zbootstrap_message zbootstrap "expanding fpath with '$fpath_extra'" + global_fpath_expand vanilla + zbootstrap_message zbootstrap "done loading noninteractive config" +} + +function zbootstrap () +{ + zbootstrap_noninteractive + zconfig_checkload ${globaldots_path}/config/zsh/global.style.zsh + zbootstrap_message zbootstrap "done loading interactive config" +} diff --git a/oh-my-zsh/plugins/battery-status/battery-status.plugin.zsh b/oh-my-zsh/plugins/battery-status/battery-status.plugin.zsh new file mode 100644 index 0000000..825764e --- /dev/null +++ b/oh-my-zsh/plugins/battery-status/battery-status.plugin.zsh @@ -0,0 +1,190 @@ +########################################### +# Battery plugin for oh-my-zsh # +# Original Author: Peter hoeg (peterhoeg) # +# Email: peter@speartail.com # +########################################### +# Author: Sean Jones (neuralsandwich) # +# Email: neuralsandwich@gmail.com # +# Modified to add support for Apple Mac # +########################################### + +if [[ "$OSTYPE" = darwin* ]] ; then + + function battery_pct() { + local smart_battery_status="$(ioreg -rc "AppleSmartBattery")" + typeset -F maxcapacity=$(echo $smart_battery_status | grep '^.*"MaxCapacity"\ =\ ' | sed -e 's/^.*"MaxCapacity"\ =\ //') + typeset -F currentcapacity=$(echo $smart_battery_status | grep '^.*"CurrentCapacity"\ =\ ' | sed -e 's/^.*CurrentCapacity"\ =\ //') + integer i=$(((currentcapacity/maxcapacity) * 100)) + echo $i + } + + function plugged_in() { + [ $(ioreg -rc AppleSmartBattery | grep -c '^.*"ExternalConnected"\ =\ Yes') -eq 1 ] + } + + function battery_pct_remaining() { + if plugged_in ; then + echo "External Power" + else + battery_pct + fi + } + + function battery_time_remaining() { + local smart_battery_status="$(ioreg -rc "AppleSmartBattery")" + if [[ $(echo $smart_battery_status | grep -c '^.*"ExternalConnected"\ =\ No') -eq 1 ]] ; then + timeremaining=$(echo $smart_battery_status | grep '^.*"AvgTimeToEmpty"\ =\ ' | sed -e 's/^.*"AvgTimeToEmpty"\ =\ //') + if [ $timeremaining -gt 720 ] ; then + echo "::" + else + echo "~$((timeremaining / 60)):$((timeremaining % 60))" + fi + else + echo "∞" + fi + } + + function battery_pct_prompt () { + if [[ $(ioreg -rc AppleSmartBattery | grep -c '^.*"ExternalConnected"\ =\ No') -eq 1 ]] ; then + b=$(battery_pct_remaining) + if [ $b -gt 50 ] ; then + color='green' + elif [ $b -gt 20 ] ; then + color='yellow' + else + color='red' + fi + echo "%{$fg[$color]%}[$(battery_pct_remaining)%%]%{$reset_color%}" + else + echo "∞" + fi + } + + function battery_is_charging() { + [[ $(ioreg -rc "AppleSmartBattery"| grep '^.*"IsCharging"\ =\ ' | sed -e 's/^.*"IsCharging"\ =\ //') == "Yes" ]] + } + +elif [[ "$OSTYPE" = linux* ]] && [[ -d /sys/class/power_supply/battery ]] ; then + + function battery_is_charging() { + [[ $(cat /sys/class/power_supply/battery/status) == "Charging" ]] + } + + function battery_pct() { + if [[ -z ${BATTERY_PCT_FAUX} ]] ;then + cat /sys/class/power_supply/battery/capacity + else + echo ${BATTERY_PCT_FAUX} + fi + } + + function battery_pct_remaining() { + if [ ! $(battery_is_charging) ] ; then + battery_pct + else + echo "External Power" + fi + } + + function battery_time_remaining() { + if [[ $(acpi 2>/dev/null | grep -c '^Battery.*Discharging') -gt 0 ]] ; then + echo $(acpi 2>/dev/null | cut -f3 -d ',') + fi + } + + function battery_pct_prompt() { + b=$(battery_pct_remaining) + if [[ $(acpi 2>/dev/null | grep -c '^Battery.*Discharging') -gt 0 ]] ; then + if [ $b -gt 50 ] ; then + color=$fg[green] + elif [ $b -gt 20 ] ; then + color=$fg[yellow] + elif [ $b -gt 5 ] ; then + color=$fg[red] + else + color=$'\033\['$color[blink]\;$color[red]m + fi + echo "%{$fg[$color]%}$(battery_pct_remaining)%%%{$reset_color%}" + else + echo "∞" + fi + } + +elif [[ "$OSTYPE" = linux* ]] && termux-battery-stat ; then + + # termux + function battery_pct_remaining() { + } + + function battery_time_remaining() { + } + + function battery_pct_prompt() { + } + +else + # Empty functions so we don't cause errors in prompts + function battery_pct_remaining() { + } + + function battery_time_remaining() { + } + + function battery_pct_prompt() { + } +fi + +function battery_level_gauge() { + # BEGIN customization + local gauge_slots=${BATTERY_GAUGE_SLOTS:-10}; + + local green_threshold=${BATTERY_GREEN_THRESHOLD:-60}; + local yellow_threshold=${BATTERY_YELLOW_THRESHOLD:-25}; + local red_threshold=${BATTERY_RED_THRESHOLD:-5}; + local color_green=${BATTERY_COLOR_GREEN:-%F{green}}; + local color_yellow=${BATTERY_COLOR_YELLOW:-%F{yellow}}; + local color_red=${BATTERY_COLOR_RED:-%F{red}}; + local color_critical=${BATTERY_COLOR_CRITICAL:-$'\033\[05\;31m'}; + + local battery_prefix=${BATTERY_GAUGE_PREFIX:-'┃'}; + local battery_suffix=${BATTERY_GAUGE_SUFFIX:-'┣'}; + local filled_symbol=${BATTERY_GAUGE_FILLED_SYMBOL:-'█'}; + local empty_symbol=${BATTERY_GAUGE_EMPTY_SYMBOL:-' '}; + local charging_color=${BATTERY_CHARGING_COLOR:-$color_yellow}; + local charging_symbol=${BATTERY_CHARGING_SYMBOL:-'⌁'}; + #END customization + + # not supposed to be changed + local gauge_subslots=7 + local gauge_slot_size=$((100/$gauge_slots)) + local -a gauge_chars=(▏ ▎ ▍ ▌ ▋ ▊ ▉) + local color_reset=${BATTERY_COLOR_RESET:-%{%f%k%b%}}; + local battery_remaining_percentage=$(battery_pct); + + if [[ $battery_remaining_percentage =~ [0-9]+ ]]; then + local filled=$(( ($battery_remaining_percentage) * $gauge_slots / 100 )); + local halfsymbol=$(( ( $battery_remaining_percentage % $gauge_slot_size * ($gauge_subslots+1) * gauge_slots / 100 ) )) + local empty=$(($gauge_slots - $filled - 1 + 0 ** halfsymbol )); + + if [[ $battery_remaining_percentage -gt $green_threshold ]]; then local gauge_color=$color_green; + elif [[ $battery_remaining_percentage -gt $yellow_threshold ]]; then local gauge_color=$color_yellow; + elif [[ $battery_remaining_percentage -gt $red_threshold ]]; then local gauge_color=$color_red; + else local gauge_color=$color_critical; + fi + else + local filled=$gauge_slots; + local empty=0; + filled_symbol=${BATTERY_UNKNOWN_SYMBOL:-'.'}; + fi + + local charging=' ' && battery_is_charging && charging=$charging_symbol; + + printf ${charging_color//\%/\%\%}$charging${color_reset//\%/\%\%}${battery_prefix//\%/\%\%}${gauge_color//\%/\%\%} + [[ $filled -gt 0 ]] && printf ${filled_symbol//\%/\%\%}'%.0s' {1..$filled} + printf '%s' $gauge_chars[${halfsymbol}] + [[ $empty -gt 0 ]] && printf ${empty_symbol//\%/\%\%}'%.0s' {1..$empty} + printf ${color_reset//\%/\%\%}${battery_suffix//\%/\%\%}${color_reset//\%/\%\%} + # printf " debug: f=%i, s='%s' e=%i " $filled "$halfsymbol" $empty +} + + diff --git a/oh-my-zsh/plugins/battery-status/battery-status.plugin.zsh.save b/oh-my-zsh/plugins/battery-status/battery-status.plugin.zsh.save new file mode 100644 index 0000000..ccce6bd --- /dev/null +++ b/oh-my-zsh/plugins/battery-status/battery-status.plugin.zsh.save @@ -0,0 +1,171 @@ +########################################### +# Battery plugin for oh-my-zsh # +# Original Author: Peter hoeg (peterhoeg) # +# Email: peter@speartail.com # +########################################### +# Author: Sean Jones (neuralsandwich) # +# Email: neuralsandwich@gmail.com # +# Modified to add support for Apple Mac # +########################################### + +if [[ "$OSTYPE" = darwin* ]] ; then + + function battery_pct() { + local smart_battery_status="$(ioreg -rc "AppleSmartBattery")" + typeset -F maxcapacity=$(echo $smart_battery_status | grep '^.*"MaxCapacity"\ =\ ' | sed -e 's/^.*"MaxCapacity"\ =\ //') + typeset -F currentcapacity=$(echo $smart_battery_status | grep '^.*"CurrentCapacity"\ =\ ' | sed -e 's/^.*CurrentCapacity"\ =\ //') + integer i=$(((currentcapacity/maxcapacity) * 100)) + echo $i + } + + function plugged_in() { + [ $(ioreg -rc AppleSmartBattery | grep -c '^.*"ExternalConnected"\ =\ Yes') -eq 1 ] + } + + function battery_pct_remaining() { + if plugged_in ; then + echo "External Power" + else + battery_pct + fi + } + + function battery_time_remaining() { + local smart_battery_status="$(ioreg -rc "AppleSmartBattery")" + if [[ $(echo $smart_battery_status | grep -c '^.*"ExternalConnected"\ =\ No') -eq 1 ]] ; then + timeremaining=$(echo $smart_battery_status | grep '^.*"AvgTimeToEmpty"\ =\ ' | sed -e 's/^.*"AvgTimeToEmpty"\ =\ //') + if [ $timeremaining -gt 720 ] ; then + echo "::" + else + echo "~$((timeremaining / 60)):$((timeremaining % 60))" + fi + else + echo "∞" + fi + } + + function battery_pct_prompt () { + if [[ $(ioreg -rc AppleSmartBattery | grep -c '^.*"ExternalConnected"\ =\ No') -eq 1 ]] ; then + b=$(battery_pct_remaining) + if [ $b -gt 50 ] ; then + color='green' + elif [ $b -gt 20 ] ; then + color='yellow' + else + color='red' + fi + echo "%{$fg[$color]%}[$(battery_pct_remaining)%%]%{$reset_color%}" + else + echo "∞" + fi + } + + function battery_is_charging() { + [[ $(ioreg -rc "AppleSmartBattery"| grep '^.*"IsCharging"\ =\ ' | sed -e 's/^.*"IsCharging"\ =\ //') == "Yes" ]] + } + +elif [[ "$OSTYPE" = linux* ]] ; then + + function battery_is_charging() { + [[ $(cat /sys/class/power_supply/battery/charging_enabled) -eq 1 ]] + } + + function battery_pct() { + cat /sys/class/power_supply/battery/capacity + } + + function battery_pct_remaining() { + if [ ! $(battery_is_charging) ] ; then + battery_pct + else + echo "External Power" + fi + } + + function battery_time_remaining() { + if [[ $(acpi 2>/dev/null | grep -c '^Battery.*Discharging') -gt 0 ]] ; then + echo $(acpi 2>/dev/null | cut -f3 -d ',') + fi + } + + function battery_pct_prompt() { + b=$(battery_pct_remaining) + if [[ $(acpi 2>/dev/null | grep -c '^Battery.*Discharging') -gt 0 ]] ; then + if [ $b -gt 50 ] ; then + color=$fg[green] + elif [ $b -gt 20 ] ; then + color=$fg[yellow] + elif [ $b -gt 5 ] ; then + color=$fg[red] + else + color=$'\033\['$color[blink]\;$color[red]m + fi + echo "%{$fg[$color]%}$(battery_pct_remaining)%%%{$reset_color%}" + else + echo "∞" + fi + } + +else + # Empty functions so we don't cause errors in prompts + function battery_pct_remaining() { + } + + function battery_time_remaining() { + } + + function battery_pct_prompt() { + } +fi + +function battery_level_gauge() { + local gauge_slots=${BATTERY_GAUGE_SLOTS:-10}; + local gauge_subslots=7 + local -a gauge_subsyms=(▏ ▎ ▍ ▌ ▋ ▊ ▉) + + local green_threshold=${BATTERY_GREEN_THRESHOLD:-60}; + local yellow_threshold=${BATTERY_YELLOW_THRESHOLD:-40}; + local red_threshold=${BATTERY_RED_THRESHOLD:-25}; + + local color_green=${BATTERY_COLOR_GREEN:-%F{green}}; + local color_yellow=${BATTERY_COLOR_YELLOW:-%F{yellow}}; + local color_red=${BATTERY_COLOR_RED:-%F{red}}; + local color_critical=${BATTERY_COLOR_CRITICAL:-$'\033\[05\;31m'}; + + local battery_prefix=${BATTERY_GAUGE_PREFIX:-'['}; + local battery_suffix=${BATTERY_GAUGE_SUFFIX:-']'}; + local filled_symbol=${BATTERY_GAUGE_FILLED_SYMBOL:-'▶'}; + local empty_symbol=${BATTERY_GAUGE_EMPTY_SYMBOL:-'▷'}; + local charging_symbol=${BATTERY_CHARGING_SYMBOL:-'🔌'}; + + local charging_color=${BATTERY_CHARGING_COLOR:-$color_yellow}; + + local color_reset=${BATTERY_COLOR_RESET:-%{%f%k%b%}}; + + local battery_remaining_percentage=$(battery_pct); + + if [[ $battery_remaining_percentage =~ [0-9]+ ]]; then + local filled=$(((( $battery_remaining_percentage * $gauge_slots - 1) / 100))); + local empty=$(($gauge_slots - $filled -1)); + local subslot=$gauge_subsyms[$(( $gauge_subslots ))] + + if [[ $battery_remaining_percentage -gt $green_threshold ]]; then local gauge_color=$color_green; + elif [[ $battery_remaining_percentage -gt $yellow_threshold ]]; then local gauge_color=$color_yellow; + elif [[ $battery_remaining_percentage -gt $red_threshold ]]; then local gauge_color=$color_red; + else local gauge_color$color_critical; + fi + else + local filled=$gauge_slots; + local empty=0; + filled_symbol=${BATTERY_UNKNOWN_SYMBOL:-'.'}; + fi + + local charging=' ' && battery_is_charging && charging=$charging_symbol; + + printf ${charging_color//\%/\%\%}$charging${color_reset//\%/\%\%}${battery_prefix//\%/\%\%}${gauge_color//\%/\%\%} + printf ${filled_symbol//\%/\%\%}'%.0s' {1..$filled} + [[ $filled -lt $gauge_slots ]] && printf ${empty_symbol//\%/\%\%}'%.0s' {1..$empty} + printf ${color_reset//\%/\%\%}${battery_suffix//\%/\%\%}${color_reset//\%/\%\%} +} + + diff --git a/oh-my-zsh/plugins/gentoo/gentoo.plugin.zsh b/oh-my-zsh/plugins/gentoo/gentoo.plugin.zsh new file mode 100644 index 0000000..b6c61cf --- /dev/null +++ b/oh-my-zsh/plugins/gentoo/gentoo.plugin.zsh @@ -0,0 +1,60 @@ +_package_edit() +{ + local context state state_descr line + typeset -A opt_args + local curcontext="$curcontext" + + _arguments -C \ + "1:portage_conftype:->conftype"\ + "2:portage_conffile:->confname" + + case $state in + conftype) + _arguments ':Portage Type:(accept_keywords accept_restrict env keywords license mask properties unmask use)' + ;; + confname) + local -a conffiles + conffiles=(/etc/portage/package.$words[2]/*(:t)) + #printf '\n\n\n\n\naaaaa->%s<-aaaaa%saaaa\n\n\n\n' "$conffiles" "$words" + #_arguments "2:portage_conffile:($conffiles)" + if [[ $words[3] =~ '\w{3,}' ]]; then + _message -r "maybe you need one of these:"$'\n'"$(cd /etc/portage/package.$words[2] 2>& - && grep -lFR $words[3] ./)" + fi + _values "Portage conffile" $conffiles + ;; + esac +} + + +package_edit() +{ + + local __su_mkdi=${__su_mkdir:-sudo mkdir} + local __su_editor=${__su_editor:-sudoedit} + local SUDO_EDITOR='vim -S /etc/vim/portage-'$1'-rc' + #local SUDO_EDITOR="nano -w -Y /etc/portage" + + + if [[ -d /etc/portage/package.$1 ]] { + env SUDO_EDITOR="${SUDO_EDITOR}" $__su_editor /etc/portage/package.$1/$2 + } elif [[ -n $2 ]] { + $__su_mkdir etc/portage/package.$1 + env SUDO_EDITOR="${SUDO_EDITOR}" $__su_editor /etc/portage/package.$1/$2 + } else { + env SUDO_EDITOR="${SUDO_EDITOR}" $__su_editor /etc/portage/package.$1 + } +} + + +alias p.env="package_edit env" +alias p.um="package_edit unmask" +alias p.akw="package_edit accept_keywords" +alias p.use="package_edit use" +alias p.mask="package_edit mask" +alias p.lic="package_edit license" +alias mk.conf="sudoedit /etc/portage/make.conf" +alias e-upd="sudo etc-update" +alias s-upd="sudo emerge --update --deep --tree --with-bdeps=y @world" +alias system-update="sudo emerge --update --deep --tree --with-bdeps=y @world" + +compdef _package_edit package_edit diff --git a/oh-my-zsh/plugins/mpvanime/mpvanime.plugin.zsh b/oh-my-zsh/plugins/mpvanime/mpvanime.plugin.zsh new file mode 100755 index 0000000..9bab8f2 --- /dev/null +++ b/oh-my-zsh/plugins/mpvanime/mpvanime.plugin.zsh @@ -0,0 +1,6 @@ +function mpvanime () { + SCRSHOT=$1 + shift + mpv --profile=anime-mode --screenshot-directory=/home/accel/Pictures/screenshots/vid/$SCRSHOT $* +} +compdef _mpv mpvanime diff --git a/oh-my-zsh/plugins/portage-edit/portage-edit.plugin.zsh b/oh-my-zsh/plugins/portage-edit/portage-edit.plugin.zsh new file mode 100644 index 0000000..e69de29 diff --git a/oh-my-zsh/plugins/prompt-automatic-refresh/prompt-automatic-refresh.plugin.zsh b/oh-my-zsh/plugins/prompt-automatic-refresh/prompt-automatic-refresh.plugin.zsh new file mode 100644 index 0000000..660dad6 --- /dev/null +++ b/oh-my-zsh/plugins/prompt-automatic-refresh/prompt-automatic-refresh.plugin.zsh @@ -0,0 +1,2 @@ +zmodload zsh/sched + diff --git a/oh-my-zsh/plugins/ssh-agent/README.md b/oh-my-zsh/plugins/ssh-agent/README.md new file mode 100644 index 0000000..00af42f --- /dev/null +++ b/oh-my-zsh/plugins/ssh-agent/README.md @@ -0,0 +1,38 @@ +# ssh-agent plugin + +This plugin starts automatically `ssh-agent` to set up and load whichever +credentials you want for ssh connections. + +To enable it, add `ssh-agent` to your plugins: + +```zsh +plugins=(... ssh-agent) +``` + +## Instructions + +To enable **agent forwarding support** add the following to your zshrc file: + +```zsh +zstyle :omz:plugins:ssh-agent agent-forwarding on +``` + +To **load multiple identities** use the `identities` style, For example: + +```zsh +zstyle :omz:plugins:ssh-agent identities id_rsa id_rsa2 id_github +``` + +To **set the maximum lifetime of the identities**, use the `lifetime` style. +The lifetime may be specified in seconds or as described in sshd_config(5) +(see _TIME FORMATS_). If left unspecified, the default lifetime is forever. + +```zsh +zstyle :omz:plugins:ssh-agent lifetime 4h +``` + +## Credits + +Based on code from Joseph M. Reagle: http://www.cygwin.com/ml/cygwin/2001-06/msg00537.html + +Agent-forwarding support based on ideas from Florent Thoumie and Jonas Pfenniger diff --git a/oh-my-zsh/plugins/ssh-agent/ssh-agent.plugin.zsh b/oh-my-zsh/plugins/ssh-agent/ssh-agent.plugin.zsh new file mode 100644 index 0000000..20f97c6 --- /dev/null +++ b/oh-my-zsh/plugins/ssh-agent/ssh-agent.plugin.zsh @@ -0,0 +1,42 @@ +typeset _agent_forwarding _ssh_env_cache + +function _start_agent() { + local lifetime + local -a identities + + # start ssh-agent and setup environment + zstyle -s :omz:plugins:ssh-agent lifetime lifetime + + ssh-agent -s ${lifetime:+-t} ${lifetime} | sed 's/^echo/#echo/' >! $_ssh_env_cache + chmod 600 $_ssh_env_cache + . $_ssh_env_cache > /dev/null + + # load identies + zstyle -a :omz:plugins:ssh-agent identities identities + + echo starting ssh-agent... + ssh-add $HOME/.ssh/${^identities} +} + +# Get the filename to store/lookup the environment from +_ssh_env_cache="$HOME/.ssh/environment-$SHORT_HOST" + +# test if agent-forwarding is enabled +zstyle -b :omz:plugins:ssh-agent agent-forwarding _agent_forwarding + +if [[ $_agent_forwarding == "yes" && -n "$SSH_AUTH_SOCK" ]]; then + # Add a nifty symlink for screen/tmux if agent forwarding + [[ -L $SSH_AUTH_SOCK ]] || ln -sf "$SSH_AUTH_SOCK" /tmp/ssh-agent-$USER-screen +elif [[ -f "$_ssh_env_cache" ]]; then + # Source SSH settings, if applicable + . $_ssh_env_cache > /dev/null + ps x | grep ssh-agent | grep -q $SSH_AGENT_PID || { + _start_agent + } +else + _start_agent +fi + +# tidy up after ourselves +unset _agent_forwarding _ssh_env_cache +unfunction _start_agent diff --git a/oh-my-zsh/plugins/tmux/tmux.extra.conf b/oh-my-zsh/plugins/tmux/tmux.extra.conf new file mode 100644 index 0000000..beffd38 --- /dev/null +++ b/oh-my-zsh/plugins/tmux/tmux.extra.conf @@ -0,0 +1,2 @@ +set -g default-terminal $ZSH_TMUX_TERM +source $HOME/.tmux.conf diff --git a/oh-my-zsh/plugins/tmux/tmux.only.conf b/oh-my-zsh/plugins/tmux/tmux.only.conf new file mode 100644 index 0000000..0734df3 --- /dev/null +++ b/oh-my-zsh/plugins/tmux/tmux.only.conf @@ -0,0 +1 @@ +set -g default-terminal $ZSH_TMUX_TERM diff --git a/oh-my-zsh/plugins/tmux/tmux.plugin.zsh b/oh-my-zsh/plugins/tmux/tmux.plugin.zsh new file mode 100644 index 0000000..f83d110 --- /dev/null +++ b/oh-my-zsh/plugins/tmux/tmux.plugin.zsh @@ -0,0 +1,112 @@ +# +# Aliases +# + +alias ta='tmux attach -t' +alias tad='tmux attach -d -t' +alias ts='tmux new-session -s' +alias tl='tmux list-sessions' +alias tksv='tmux kill-server' +alias tkss='tmux kill-session -t' + +# Only run if tmux is actually installed +if which tmux &> /dev/null + then + # Configuration variables + # + # Automatically start tmux + [[ -n "$ZSH_TMUX_AUTOSTART" ]] || ZSH_TMUX_AUTOSTART=false + # Only autostart once. If set to false, tmux will attempt to + # autostart every time your zsh configs are reloaded. + [[ -n "$ZSH_TMUX_AUTOSTART_ONCE" ]] || ZSH_TMUX_AUTOSTART_ONCE=true + # Automatically connect to a previous session if it exists + [[ -n "$ZSH_TMUX_AUTOCONNECT" ]] || ZSH_TMUX_AUTOCONNECT=true + # Automatically close the terminal when tmux exits + [[ -n "$ZSH_TMUX_AUTOQUIT" ]] || ZSH_TMUX_AUTOQUIT=$ZSH_TMUX_AUTOSTART + # Set term to screen or screen-256color based on current terminal support + [[ -n "$ZSH_TMUX_FIXTERM" ]] || ZSH_TMUX_FIXTERM=true + # Set '-CC' option for iTerm2 tmux integration + [[ -n "$ZSH_TMUX_ITERM2" ]] || ZSH_TMUX_ITERM2=false + # The TERM to use for non-256 color terminals. + # Tmux states this should be screen, but you may need to change it on + # systems without the proper terminfo + [[ -n "$ZSH_TMUX_FIXTERM_WITHOUT_256COLOR" ]] || ZSH_TMUX_FIXTERM_WITHOUT_256COLOR="screen" + # The TERM to use for 256 color terminals. + # Tmux states this should be screen-256color, but you may need to change it on + # systems without the proper terminfo + [[ -n "$ZSH_TMUX_FIXTERM_WITH_256COLOR" ]] || ZSH_TMUX_FIXTERM_WITH_256COLOR="screen-256color" + + + # Get the absolute path to the current directory + local zsh_tmux_plugin_path="$(cd "$(dirname "$0")" && pwd)" + + # Determine if the terminal supports 256 colors + if [[ `tput colors` == "256" ]] + then + export ZSH_TMUX_TERM=$ZSH_TMUX_FIXTERM_WITH_256COLOR + else + export ZSH_TMUX_TERM=$ZSH_TMUX_FIXTERM_WITHOUT_256COLOR + fi + + # Set the correct local config file to use. + if [[ "$ZSH_TMUX_ITERM2" == "false" ]] && [[ -f $HOME/.tmux.conf || -h $HOME/.tmux.conf ]] + then + #use this when they have a ~/.tmux.conf + export _ZSH_TMUX_FIXED_CONFIG="$zsh_tmux_plugin_path/tmux.extra.conf" + else + #use this when they don't have a ~/.tmux.conf + export _ZSH_TMUX_FIXED_CONFIG="$zsh_tmux_plugin_path/tmux.only.conf" + fi + + # Wrapper function for tmux. + function _zsh_tmux_plugin_run() + { + # We have other arguments, just run them + if [[ -n "$@" ]] + then + if [[ "$1" == 'attach' ]] + then + if [[ "$3" =~ '^-' ]] + then + title '[tmux] '\""$4"\" + else + title '[tmux] '\""$3"\" + fi + elif [[ "$1" == 'new-session' ]] + then + title '[tmux] '\""$3"\" + else + title "tmux $*" + fi + \tmux $@ + # Try to connect to an existing session. + elif [[ "$ZSH_TMUX_AUTOCONNECT" == "true" ]] + then + \tmux `[[ "$ZSH_TMUX_ITERM2" == "true" ]] && echo '-CC '` attach || \tmux `[[ "$ZSH_TMUX_ITERM2" == "true" ]] && echo '-CC '` `[[ "$ZSH_TMUX_FIXTERM" == "true" ]] && echo '-f '$_ZSH_TMUX_FIXED_CONFIG` new-session + [[ "$ZSH_TMUX_AUTOQUIT" == "true" ]] && exit + # Just run tmux, fixing the TERM variable if requested. + else + \tmux `[[ "$ZSH_TMUX_ITERM2" == "true" ]] && echo '-CC '` `[[ "$ZSH_TMUX_FIXTERM" == "true" ]] && echo '-f '$_ZSH_TMUX_FIXED_CONFIG` + [[ "$ZSH_TMUX_AUTOQUIT" == "true" ]] && exit + fi + } + + # Use the completions for tmux for our function + compdef _tmux _zsh_tmux_plugin_run + + # Alias tmux to our wrapper function. + alias tmux=_zsh_tmux_plugin_run + + # Autostart if not already in tmux and enabled. + if [[ ! -n "$TMUX" && "$ZSH_TMUX_AUTOSTART" == "true" ]] + then + # Actually don't autostart if we already did and multiple autostarts are disabled. + if [[ "$ZSH_TMUX_AUTOSTART_ONCE" == "false" || "$ZSH_TMUX_AUTOSTARTED" != "true" ]] + then + export ZSH_TMUX_AUTOSTARTED=true + _zsh_tmux_plugin_run + fi + fi +else + print "zsh tmux plugin: tmux not found. Please install tmux before using this plugin." +fi diff --git a/zbootstrap.zsh b/zbootstrap.zsh new file mode 100644 index 0000000..809b8c6 --- /dev/null +++ b/zbootstrap.zsh @@ -0,0 +1,14 @@ +if [[ -n ${GLOBALDOTS_PATH} ]] +then + typeset -g globaldots_path=${GLOBALDOTS_PATH} +else +if [[ -a $(realpath -m $(dirname $0)/../../.globaldir ) ]] +then + typeset -g globaldots_path=$(realpath -m $(dirname $0)/../../) +else + typeset -g globaldots_path="${GLOBALDOTS_PATH:-${HOME}/.global}" +fi +fi + +source ${globaldots_path}/lib/zsh/global.funcs.zsh +source ${globaldots_path}/lib/zsh/zssh.funcs.zsh diff --git a/zssh.funcs.zsh b/zssh.funcs.zsh new file mode 100644 index 0000000..a4b0386 --- /dev/null +++ b/zssh.funcs.zsh @@ -0,0 +1,227 @@ +function zssh_boot() +{ + typeset -g zssh_ssh_dotdir="${HOME}/.ssh" + typeset -g zssh_private_keys="${zssh_ssh_dotdir}/keystore" + typeset -g zssh_private_configs="${zssh_ssh_dotdir}/config.d" + typeset -g zssh_global_configs=${globaldots_path}/config/ssh + typeset -g zssh_global_pubkeys=${globaldots_path}/keys/ssh + zssh_configure + zssh_process +} + +function zssh_configure () +{ + if [[ -n "$zssh_host" ]] + then + zbootstrap_message zssh "zssh_host is set" + ztools_ensure -d $zssh_private_keys + ztools_ensure -d $zssh_private_configs + ztools_ensure -d ${zssh_global_configs} + ztools_ensure -d ${zssh_global_pubkeys} + zssh_enumeratenodes + if [[ ${#zssh_host_config_accesses} -gt 0 ]] + then + zbootstrap_message zssh "zssh_host_config_accesses is set" + typeset -g zssh_global_config_hostdir="${zssh_global_configs}/${zssh_host}" + typeset -g zssh_global_pubkey_hostdir="${zssh_global_pubkeys}/${zssh_host}" + ztools_ensure -d "${zssh_global_pubkey_hostdir}" + ztools_ensure -d "${zssh_global_config_hostdir}" + else + zbootstrap_message zssh "zssh_host_config_accesses is NOT set, not going to bother accepting keys" + fi + else + zbootstrap_message zssh "zssh_host is NOT set, which means we cannot neither publish keys nor accept them" + fi +} + +function zssh_process() +{ + if [[ -n "$zssh_host" ]] + then + if [[ ${#zssh_host_config_accesses} -gt 0 ]] + then + zbootstrap_message zssh "processing ssh server setup" + if [[ "${HOME}/.config/zsh/local.config.zsh" -nt "${zssh_global_config_hostdir}" ]] + then + zbootstrap_message zssh "publishing our configs …" + zssh_publish_configs + else + zbootstrap_message zssh "not publishing our configs …" + fi + fi + zbootstrap_message zssh "processing ssh client setup" + zssh_install_peers + zssh_publish_pubkeys + fi +} + +function zssh_install_peers() +{ + [[ -n $zssh_host ]] || return 63 + zbootstrap_message zssh "installing peers" + for ssh_node in $zssh_nodes + do + zbootstrap_message zssh "installing peer $ssh_node …" + zssh_generate_privkey4 $ssh_node + zssh_generate_config4 $ssh_node + done +} + +function zssh_publish_pubkeys() +{ + for ssh_node in $zssh_nodes + do + zssh_mail_pubkey2 $ssh_node + done +} + +function zssh_mail_pubkey2() +{ + [[ -n $zssh_host ]] || return 63 + ssh_node="$1" + local targetspool="$zssh_global_pubkeys/$ssh_node" + local srcpk="$zssh_private_keys/$ssh_node.key.pub" + ztools_ensure -d "${targetspool}" + cp -t "$targetspool" "$srcpk" +} + +function zssh_publish_configs() +{ + [[ -n "$zssh_host_config_accesses" ]] || return 62 + for sshmatch in ${(k)zssh_host_config_accesses} + do + hostaccessconfig_file="${zssh_global_config_hostdir}/${sshmatch}.sshconf" + zbootstrap_message zssh "generating our server access config '${hostaccessconfig_file}'" + zssh_generate_hostaccessconfig $sshmatch > "$hostaccessconfig_file" + done + zbootstrap_message zssh "updating mtime for ${zssh_global_config_hostdir}" + touch "${zssh_global_config_hostdir}" +} + +function zssh_generate_hostaccessconfig() +{ + sshmatch="${1}" + sshcontents=${zssh_host_config_accesses[$sshmatch]} + sshmatch_user=${sshmatch%%@*} + sshmatch_host=${sshmatch##*@} + if [[ "$sshmatch_host" == "$sshmatch_user" ]] + then + sshmatch_user='' + fi + << HERE +Match ${sshmatch_host:+host $sshmatch_host,} ${sshmatch_user:+user $sshmatch_user,} + ${sshcontents} + ${zssh_host_config} +HERE +} + +function zssh_generate_config4 +{ + ssh_node="$1" + dst="$zssh_private_configs/$ssh_node.sshconf" + srcs="$zssh_global_configs/$ssh_node" + zbootstrap_message zssh "checking configs for $ssh_node …" + if [[ -d "$srcs" ]] && ! [[ $dst -nt $srcs ]] + then + sshkey="$zssh_private_keys/$ssh_node.key" + zbootstrap_message zssh "found fresh configs directory for $ssh_node" + zbootstrap_message zssh "config destination is '$dst'" + zbootstrap_message zssh "tied ssh key is '$sshkey'" + rm "$dst" 2> /dev/null + for src in "$srcs"/*.sshconf(N) + do + zbootstrap_message zssh "sourcing $src" + cat "$src" >> "$dst" + printf "\n IdentityFile %s\n\n" "$sshkey" >> "$dst" + done + fi + zbootstrap_message zssh "done with $ssh_node" +} + +function zssh_generate_privkey4 +{ + ssh_node="$1" + zbootstrap_message zssh "checking keys for peer $ssh_node …" + local newkey=$zssh_private_keys/$ssh_node.key + if ! [[ -s $newkey ]] + then + zbootstrap_message zssh "generate key for $ssh_node" + ssh-keygen -t ed25519 -N '' -C "$ssh_host($USER@$HOST) for $ssh_node" -f $newkey >> "${HOME}/.log/ssh-keygen.log" + if [[ "$ssh_node" == "$zssh_host" ]] + then + zbootstrap_message zssh "Self accepting key: $ssh_node" + cat "$newkey.pub" >> ${HOME}/.ssh/authorized_keys + fi + fi +} + +function zssh_offer_all() +{ + # offers keys for every node + if ! [[ -d $zssh_private_keys ]] + then + zbootstrap_message zssh "$zssh_private_keys not found" + return + fi + if [[ -n $zssh_thishost ]] + then + for ssh_node in $zssh_nodes + do + local node_directory=$zssh_global_configs/$ssh_node + local keytooffer=$node_directory/keyoffers/$zssh_thishost.pub + local keysource=$zssh_private_keys/$ssh_node.key + if ! [[ -s $keysource ]] + then + zbootstrap_message zssh "$ssh_node misses $keysource private key in keystore" + continue + fi + if ! [[ -d $node_directory ]] + then + zbootstrap_message zssh "$ssh_node misses its config directory '$node_directory'" + continue + fi + if ! [[ -d $node_directory/keyoffers ]] + then + zbootstrap_message zssh "creating keyoffer directory for $ssh_node" + mkdir $node_directory/keyoffers + fi + # offering ... + if ! [[ -s $keytooffer ]] + then + zbootstrap_message zssh "Offering public key for $ssh_node" + ssh-keygen -y -f $keysource -C "$zssh_thishost offered to ${ssh_node}" > $keytooffer + fi + done + else + zbootstrap_message zssh "no zssh_thishost defined, offering skipped" + fi +} + +function zssh_accept_key() +{ + local offered=$zssh_global_configs/$zssh_thishost/keyoffer/$1.pub + cat $offered + echo "do you accept key '$1'? :" + read + if [[ $REPLY == 'Y' ]] + then + echo "key $1 accepted" + cat $offered >> ${HOME}/.ssh/authorized_keys + else + echo "key $1 NOT accepted" + fi +} + +function zssh_enumeratenodes() +{ + typeset -g -a zssh_nodes; + zbootstrap_message zssh "enumerating nodes" + if [[ -d $zssh_global_configs ]] + then + for __ssh_node in ${zssh_global_configs}/*(/) + do + zssh_nodes+=($(basename $__ssh_node)) + done + fi + zbootstrap_message zssh "got ${#zssh_nodes} nodes" +}