From 78b3209ea40b1ebf1966f18a4fc57f12bbaf5220 Mon Sep 17 00:00:00 2001 From: shokinn Date: Wed, 13 Sep 2023 11:06:14 +0200 Subject: [PATCH] reorganize dotrfiles; fix exa aliasses for mac --- config.yaml | 9 +++- dotfiles/commonfunc | 103 ++++++++++++++++++++++++++++++++++++++++++++ dotfiles/zshenv | 27 +++--------- dotfiles/zshrc | 89 +------------------------------------- 4 files changed, 119 insertions(+), 109 deletions(-) create mode 100644 dotfiles/commonfunc diff --git a/config.yaml b/config.yaml index 537ea52..73bbf66 100644 --- a/config.yaml +++ b/config.yaml @@ -128,6 +128,9 @@ dotfiles: f_rmquarantine: dst: ~/.bin/rmquarantine src: bin/rmquarantine + f_commonfunc: + dst: ~/.commonfunc + src: commonfunc profiles: AINCRAD: dotfiles: @@ -248,6 +251,7 @@ profiles: - f_wsladdhypervroute - f_wslenablehypervforwarding - f_wslshowhypervforwarding + - f_commonfunc workspace: dotfiles: - d_fonts @@ -258,6 +262,7 @@ profiles: - f_powerlevel10krc - d_colors - f_zprofile + - f_commonfunc sbx0nucmac01.home.pphg.tech: dotfiles: - f_vimrc @@ -272,6 +277,7 @@ profiles: - f_c3mpv - f_c3check - f_zprofile + - f_commonfunc WVDEWOBMC001307: dotfiles: - f_vimrc @@ -289,4 +295,5 @@ profiles: - f_dotdrop.sh - f_pu - f_rpki - - f_rmquarantine \ No newline at end of file + - f_rmquarantine + - f_commonfunc \ No newline at end of file diff --git a/dotfiles/commonfunc b/dotfiles/commonfunc new file mode 100644 index 0000000..7c26074 --- /dev/null +++ b/dotfiles/commonfunc @@ -0,0 +1,103 @@ +#! /bin/sed 2,5!d;s/^#.// +# This script must be sourced from within a shell +# and not executed. For instance with: +# +# . ~/.commonfunc + +# +# {{@@ header() @@}} +# + +# exa - set aliasses for exa to use it as ls replacement +if [[ $(command -v exa) ]]; then + exafunc() { + exa -l -F -g -h --extended --git --group-directories-first --icons ${@:-} + } + lfunc() { + exafunc -T -L ${1:-1} + } + lafunc() { + exafunc -a -T -L ${1:-1} + } + alias l='lfunc' + alias la='lafunc' + alias ll="lfunc 2" + alias lla='lafunc 2' +fi + +# wttr - show the weather forecast in Terminal +wttr() { + if [ -z "${1}" ]; then + curl http://wttr.in + elif [[ "${1}" == "help" ]]; then + cat << EOF +usage: wttr (City|3-letter airport code|'~Special+Location') + City: + Just write down the name of the city. + e.G.: + wttr London + 3-letter airport code: + Use 3-letter airport codes in order to get the weather information at a certain airport. + e.G.: + wttr muc #for Munich Internation Airpot, Germany + Special Location: + Let's say you'd like to get the weather for a geographical location other than a town or city - + maybe an attraction in a city, a mountain name, or some special location. + Add the character '~' before the name to look up that special location name before the weather is then retrieved. + e.G.: + wttr '~Eiffel+Tower' + wttr '~Kilimanjaro' +EOF + else + curl http://wttr.in/${1} + fi +} + +{%@@ if profile == 'WVDEWOBMC001307' @@%} +macnst (){ + netstat -Watnlv | grep LISTEN | awk '{"ps -o comm= -p " $9 | getline procname;colred="\033[01;31m";colclr="\033[0m"; print colred "proto: " colclr $1 colred " | addr.port: " colclr $4 colred " | pid: " colclr $9 colred " | name: " colclr procname; }' | column -t -s "|" +} + +function setProxyEnv(){ + local HIGHLIGHT='\033[36;1m' + local RESET='\033[0;0m' + + local PROXY='127.0.0.1:9000' + local PROXY_CFG_HTTP="${PROXY}" + local PROXY_CFG_HTTPS="${PROXY}" + local NO_PROXY_CFG="127.0.0.1,localhost,vw.vwg" + + export NO_PROXY="${NO_PROXY_CFG}" + export no_proxy="${NO_PROXY_CFG}" + export HTTP_PROXY="${PROXY_CFG_HTTP}" + export HTTPS_PROXY="${PROXY_CFG_HTTPS}" + export http_proxy="${PROXY_CFG_HTTP}" + export https_proxy="${PROXY_CFG_HTTPS}" + export GIT_SSH_COMMAND='ssh -o ProxyCommand="/opt/homebrew/bin/corkscrew localhost 9000 %h %p"' + + echo -e "\nāœˆļø exported zscaler proxy: ${HIGHLIGHT}http://${PROXY}${RESET}" +} + +function unsetProxyEnv(){ + unset NO_PROXY + unset HTTP_PROXY + unset HTTPS_PROXY + unset no_proxy + unset http_proxy + unset https_proxy + unset GIT_SSH_COMMAND + + echo -e "\nšŸ”„ removed zscaler proxy cofiguration" +} + +function setVpnGitRemote(){ + local ORIGIN=vpn #e.g. + local HIGHLIGHT='\033[36;1m' + local RESET='\033[0;0m' + + local repo="ssh://git@vpn.github.com:443/${$(git config remote.origin.url)#*git@github.com:}" + git remote add ${ORIGIN} "${repo}" 2> /dev/null + + echo -e "šŸ”— git remote (${HIGHLIGHT}${ORIGIN}${RESET}): ${HIGHLIGHT}${repo}${RESET}\n" +} +{%@@ endif @@%} \ No newline at end of file diff --git a/dotfiles/zshenv b/dotfiles/zshenv index f98d475..75cba33 100644 --- a/dotfiles/zshenv +++ b/dotfiles/zshenv @@ -20,29 +20,14 @@ export ANSIBLE_NOCOWS=1 # Include $(go env GOPATH) to PATH [[ $(command -v go) ]] && [[ -d "$(go env GOPATH)/bin" ]] && export PATH="$(go env GOPATH)/bin:${PATH}" -# exa -if [[ $(command -v exa) ]]; then - lfunc() { - exal -T -L ${1:-1} - } - lafunc() { - exal -a -T -L ${1:-1} - } - alias exal="exa -l -F -g -h --extended --git --group-directories-first --icons" - alias l='lfunc' - alias la='lafunc' - alias ll="lfunc 2" - alias lla='lafunc 2' -fi - {%@@ if profile == 'AINCRAD-wsl' or profile == 'AINCRAD' or profile == 'YOETUNHEIMR-wsl' or profile == 'yoetunheimr' or profile == 'ymir' @@%} # Connect to windows ssh pageant # https://github.com/BlackReloaded/wsl2-ssh-pageant export SSH_AUTH_SOCK={{@@ env['HOME'] @@}}/.ssh/agent.sock ss -a | grep -q $SSH_AUTH_SOCK if [ $? -ne 0 ]; then - rm -f $SSH_AUTH_SOCK - (setsid nohup socat UNIX-LISTEN:$SSH_AUTH_SOCK,fork EXEC:{{@@ env['HOME'] @@}}/.ssh/wsl2-ssh-pageant.exe >/dev/null 2>&1 &) + rm -f $SSH_AUTH_SOCK + (setsid nohup socat UNIX-LISTEN:$SSH_AUTH_SOCK,fork EXEC:{{@@ env['HOME'] @@}}/.ssh/wsl2-ssh-pageant.exe >/dev/null 2>&1 &) fi # Connect to windows gpg agent @@ -50,8 +35,8 @@ fi export GPG_AGENT_SOCK={{@@ env['HOME'] @@}}/.gnupg/S.gpg-agent ss -a | grep -q $GPG_AGENT_SOCK if [ $? -ne 0 ]; then - rm -rf $GPG_AGENT_SOCK - (setsid nohup socat UNIX-LISTEN:$GPG_AGENT_SOCK,fork EXEC:"{{@@ env['HOME'] @@}}/.ssh/wsl2-ssh-pageant.exe --gpg S.gpg-agent" >/dev/null 2>&1 &) + rm -rf $GPG_AGENT_SOCK + (setsid nohup socat UNIX-LISTEN:$GPG_AGENT_SOCK,fork EXEC:"{{@@ env['HOME'] @@}}/.ssh/wsl2-ssh-pageant.exe --gpg S.gpg-agent" >/dev/null 2>&1 &) fi # X410 (Windows X11 Server) @@ -60,4 +45,6 @@ export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2; exit;} {%@@ if profile == 'WVDEWOBMC001307' @@%} export HOMEBREW_CASK_OPTS="--appdir=~/Applications" -{%@@ endif @@%} \ No newline at end of file +{%@@ endif @@%} + +source {{@@ env['HOME'] @@}}/.commonfunc diff --git a/dotfiles/zshrc b/dotfiles/zshrc index 19666dc..fff7c7b 100644 --- a/dotfiles/zshrc +++ b/dotfiles/zshrc @@ -158,21 +158,6 @@ source ${ZSH}/oh-my-zsh.sh alias ssh-no-check="ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" -# exa -if [[ $(command -v exa) ]]; then - lfunc() { - exal -T -L ${1:-1} - } - lafunc() { - exal -a -T -L ${1:-1} - } - alias exal="exa -l -F -g -h --extended --git --group-directories-first --icons" - alias l='lfunc' - alias la='lafunc' - alias ll="lfunc 2" - alias lla='lafunc 2' -fi - # Initialize pyenv [[ $(command -v pyenv) ]] && export PYENV_ROOT="$HOME/.pyenv" [[ $(command -v pyenv) ]] && command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH" @@ -196,79 +181,7 @@ export PATH="${brew_path}:${PATH}" {%@@ endif @@%} # Functions (or more complex aliases) -wttr() { - if [ -z "${1}" ]; then - curl http://wttr.in - elif [[ "${1}" == "help" ]]; then - cat << EOF -usage: wttr (City|3-letter airport code|'~Special+Location') - City: - Just write down the name of the city. - e.G.: - wttr London - 3-letter airport code: - Use 3-letter airport codes in order to get the weather information at a certain airport. - e.G.: - wttr muc #for Munich Internation Airpot, Germany - Special Location: - Let's say you'd like to get the weather for a geographical location other than a town or city - - maybe an attraction in a city, a mountain name, or some special location. - Add the character '~' before the name to look up that special location name before the weather is then retrieved. - e.G.: - wttr '~Eiffel+Tower' - wttr '~Kilimanjaro' -EOF - else - curl http://wttr.in/${1} - fi -} - -{%@@ if profile == 'WVDEWOBMC001307' @@%} -macnst (){ - netstat -Watnlv | grep LISTEN | awk '{"ps -o comm= -p " $9 | getline procname;colred="\033[01;31m";colclr="\033[0m"; print colred "proto: " colclr $1 colred " | addr.port: " colclr $4 colred " | pid: " colclr $9 colred " | name: " colclr procname; }' | column -t -s "|" -} - -function setProxyEnv(){ - local HIGHLIGHT='\033[36;1m' - local RESET='\033[0;0m' - - local PROXY='127.0.0.1:9000' - local PROXY_CFG_HTTP="${PROXY}" - local PROXY_CFG_HTTPS="${PROXY}" - local NO_PROXY_CFG="127.0.0.1,localhost,vw.vwg" - - export NO_PROXY="${NO_PROXY_CFG}" - export no_proxy="${NO_PROXY_CFG}" - export HTTP_PROXY="${PROXY_CFG_HTTP}" - export HTTPS_PROXY="${PROXY_CFG_HTTPS}" - export http_proxy="${PROXY_CFG_HTTP}" - export https_proxy="${PROXY_CFG_HTTPS}" - - echo -e "\nāœˆļø exported zscaler proxy: ${HIGHLIGHT}http://${PROXY}${RESET}" -} - -function unsetProxyEnv(){ - unset NO_PROXY - unset HTTP_PROXY - unset HTTPS_PROXY - unset no_proxy - unset http_proxy - unset https_proxy - - echo -e "\nšŸ”„ removed zscaler proxy cofiguration" -} - -function setVpnGitRemote(){ - local ORIGIN=vpn #e.g. - local HIGHLIGHT='\033[36;1m' - local RESET='\033[0;0m' - - local repo="ssh://git@vpn.github.com:443/${$(git config remote.origin.url)#*git@github.com:}" - git remote add ${ORIGIN} "${repo}" 2> /dev/null - - echo -e "šŸ”— git remote (${HIGHLIGHT}${ORIGIN}${RESET}): ${HIGHLIGHT}${repo}${RESET}\n" -} -{%@@ endif @@%} +source {{@@ env['HOME'] @@}}/.commonfunc {%@@ if profile == 'ymir' @@%} autoload -Uz compinit