From c22ec9638cf3c302abdea2c05b997a99c0299533 Mon Sep 17 00:00:00 2001 From: doman Date: Tue, 14 Nov 2023 19:04:03 +0100 Subject: [PATCH] break scripts from zshrc to separate scripts --- .config/scriptrc/base16.sh | 10 +++++ .config/scriptrc/ex.sh | 21 ++++++++++ .config/scriptrc/mac.sh | 19 +++++++++ .config/scriptrc/start_tmux.sh | 6 +++ .zshrc | 71 +++++----------------------------- 5 files changed, 66 insertions(+), 61 deletions(-) create mode 100644 .config/scriptrc/base16.sh create mode 100644 .config/scriptrc/ex.sh create mode 100644 .config/scriptrc/mac.sh create mode 100644 .config/scriptrc/start_tmux.sh diff --git a/.config/scriptrc/base16.sh b/.config/scriptrc/base16.sh new file mode 100644 index 0000000..5f0fc43 --- /dev/null +++ b/.config/scriptrc/base16.sh @@ -0,0 +1,10 @@ +# Base16 Shell +if ! {[ -n "$TMUX" ] || [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]}; then + BASE16_SHELL="$HOME/.config/base16-shell/" + source "$BASE16_SHELL/profile_helper.sh" 2>/dev/null + BASE16_SHELL_SET_BACKGROUND=false +fi + +if ! {[ -n "$TMUX" ] || [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]}; then + base16_ocean +fi diff --git a/.config/scriptrc/ex.sh b/.config/scriptrc/ex.sh new file mode 100644 index 0000000..5bb85f6 --- /dev/null +++ b/.config/scriptrc/ex.sh @@ -0,0 +1,21 @@ +ex () +{ + if [ -f $1 ] ; then + case $1 in + *.tar.bz2) tar xjf $1 ;; + *.tar.gz) tar xzf $1 ;; + *.bz2) bunzip2 $1 ;; + *.rar) unrar x $1 ;; + *.gz) gunzip $1 ;; + *.tar) tar xf $1 ;; + *.tbz2) tar xjf $1 ;; + *.tgz) tar xzf $1 ;; + *.zip) unzip $1 ;; + *.Z) uncompress $1;; + *.7z) 7z x $1 ;; + *) echo "'$1' cannot be extracted via ex()" ;; + esac + else + echo "'$1' is not a valid file" + fi +} diff --git a/.config/scriptrc/mac.sh b/.config/scriptrc/mac.sh new file mode 100644 index 0000000..e205daa --- /dev/null +++ b/.config/scriptrc/mac.sh @@ -0,0 +1,19 @@ +setupmac() { + defaults write com.apple.dock expose-animation-duration -float 0.1 + defaults write -g InitialKeyRepeat -int 12 + defaults write -g KeyRepeat -int 1 + defaults write com.apple.Dock autohide-delay -float 0; killall Dock + defaults write -g com.apple.mouse.scaling -integer -1 +} + +check_ssh_add() { + if [[ "$(ssh-add -l)" == "The agent has no identities." ]] ; then + ssh-add ~/.ssh/id_rsa + setupmac + fi +} + + +if [[ "$(uname)" == "Darwin" ]]; then + check_ssh_add +fi diff --git a/.config/scriptrc/start_tmux.sh b/.config/scriptrc/start_tmux.sh new file mode 100644 index 0000000..818e90b --- /dev/null +++ b/.config/scriptrc/start_tmux.sh @@ -0,0 +1,6 @@ +# run neofetch or tmux if available +if [ ! -z "$(which tmux 2>/dev/null)" ]; then + if [ ! -n "$TMUX" ] || [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then + exec tmux + fi +fi diff --git a/.zshrc b/.zshrc index 4e9a2a2..6551bc8 100755 --- a/.zshrc +++ b/.zshrc @@ -179,20 +179,6 @@ bindkey '^R' history-incremental-search-backward bindkey '\eOH' beginning-of-line bindkey '\eOF' end-of-line -# Load aliases and shortcuts if existent. -if [ -d "$HOME/.config/aliasrc" ]; then - for ALIASFILE in $HOME/.config/aliasrc/*; do - source $ALIASFILE - done -fi - -# Load scripts -if [ -d "$HOME/.config/scriptrc" ]; then - for SCRIPTFILE in $HOME/.config/scriptrc/*; do - source $SCRIPTFILE - done -fi - # IMPORTA if [ ! -z "$(which nvim 2>/dev/null)" ]; then export EDITOR=nvim @@ -200,29 +186,6 @@ else export EDITOR=vim fi -# must have function! -ex () -{ - if [ -f $1 ] ; then - case $1 in - *.tar.bz2) tar xjf $1 ;; - *.tar.gz) tar xzf $1 ;; - *.bz2) bunzip2 $1 ;; - *.rar) unrar x $1 ;; - *.gz) gunzip $1 ;; - *.tar) tar xf $1 ;; - *.tbz2) tar xjf $1 ;; - *.tgz) tar xzf $1 ;; - *.zip) unzip $1 ;; - *.Z) uncompress $1;; - *.7z) 7z x $1 ;; - *) echo "'$1' cannot be extracted via ex()" ;; - esac - else - echo "'$1' is not a valid file" - fi -} - # load plugins source ~/.zsh/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh 2>/dev/null source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh 2>/dev/null @@ -243,30 +206,16 @@ export LDFLAGS="-L/opt/homebrew/opt/mysql-client/lib" export CPPFLAGS="-I/opt/homebrew/opt/mysql-client/include" export PKG_CONFIG_PATH="/opt/homebrew/opt/mysql-client/lib/pkgconfig" -# Base16 Shell -if ! {[ -n "$TMUX" ] || [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]}; then - BASE16_SHELL="$HOME/.config/base16-shell/" - source "$BASE16_SHELL/profile_helper.sh" 2>/dev/null - BASE16_SHELL_SET_BACKGROUND=false +# Load aliases and shortcuts if existent. +if [ -d "$HOME/.config/aliasrc" ]; then + for ALIASFILE in $HOME/.config/aliasrc/*; do + source $ALIASFILE + done fi -if ! {[ -n "$TMUX" ] || [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]}; then - base16_ocean -fi - -cached_neofetch () -{ - # [ ! -z $HOME/.neofetch_cache ] && [ ! -z "$(which neofetch 2>/dev/null)" ] && neofetch > $HOME/.neofetch_cache - # cat $HOME/.neofetch_cache 2>/dev/null -} - -# run neofetch or tmux if available -if [ ! -z "$(which tmux 2>/dev/null)" ]; then - if [ -n "$TMUX" ] || [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then - cached_neofetch - else - exec tmux - fi -else - cached_neofetch +# Load scripts +if [ -d "$HOME/.config/scriptrc" ]; then + for SCRIPTFILE in $HOME/.config/scriptrc/*; do + source $SCRIPTFILE + done fi