diff --git a/zsh/lib/aliases.zsh b/zsh/lib/aliases.zsh new file mode 100644 index 0000000..dd1f2d0 --- /dev/null +++ b/zsh/lib/aliases.zsh @@ -0,0 +1,7 @@ +alias pip=pip3 +alias vim="nvim" +alias vi="nvim" +alias vimdiff="nvim -d" +alias dlports="docker container ls --format table '{{.ID}}\t{{.Names}}\t{{.Ports}} -a'" + + diff --git a/zsh/lib/autocomplete_overrides.zsh b/zsh/lib/autocomplete_overrides.zsh new file mode 100644 index 0000000..1fe0a0e --- /dev/null +++ b/zsh/lib/autocomplete_overrides.zsh @@ -0,0 +1,19 @@ +# Fix zsh-autocomplete assumptions +# use the standard up/down history scroll, access menu with A-up/A-down +#bindkey "^[[A" .up-line-or-history +#bindkey "^[[B" .down-line-or-history + +# Use Tab and S-TAb to cycle through completions +# noac - bindkey '^I' menu-complete +# noac - bindkey "$terminfo[kcbt]" reverse-menu-complete + +# Allow the arrow keys to scroll within the selected command line input +# noac - bindkey -M menuselect '^[[D' .backward-char '^[OD' .backward-char +# noac - bindkey -M menuselect '^[[C' .forward-char '^[OC' .forward-char + +# Make [enter] submit the commandline straight from the menu, tab or arrows to edit +# noac - bindkey -M menuselect '\r' .accept-line + +# Limit autocomplete results to 1/4 of the screen height +#zstyle -e ':autocomplete:*:*' list-lines 'reply=( $(( LINES / 4 )) )' +# noac - zstyle -e ':autocomplete:*:*' list-lines 'reply=( 6 )' diff --git a/zsh/lib/git.zsh b/zsh/lib/git.zsh new file mode 100644 index 0000000..8f7405d --- /dev/null +++ b/zsh/lib/git.zsh @@ -0,0 +1,16 @@ +function git-parent-branch { + git show-branch -a \ + | grep '\*' \ + | grep -v `git-rev-parse --abbrev-ref HEAD` \ + | head -n1 \ + | sed 's/.*\[\(.*\)\].*/\1/' \ + | sed 's/[\^~].*//' +} +alias gpb=git-parent-branch + +# Use this to define the git lg alias +function define_gitlg { + git config --global alias.lg log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset' --abbrev-commit +} + + diff --git a/zsh/lib/history.zsh b/zsh/lib/history.zsh new file mode 100644 index 0000000..e726e8d --- /dev/null +++ b/zsh/lib/history.zsh @@ -0,0 +1,18 @@ +# Settings for the *omz/lib/history* +# +# Set the timestamp format for history for ISO format +export HIST_STAMPS="yyyy-mm-dd" +# Don't bother storing these commands in history +export HISTORY_IGNORE="(ls|cd|cd -|pwd|exit|date|.* --help)" +# Set the location for the zsh_history file to be inside our .zsh foler +export HISTFILE="$ZDOTDIR/.zsh_history" +# Keep this many history events in per-shell memory +export HISTSIZE=100000 +# Keep this many history events in the log file +export SAVEHIST=50000 + +unsetopt share_history +unsetopt hist_verify +setopt hist_ignore_all_dups +setopt hist_find_no_dups + diff --git a/zsh/lib/keybinds.zsh b/zsh/lib/keybinds.zsh new file mode 100644 index 0000000..a30e684 --- /dev/null +++ b/zsh/lib/keybinds.zsh @@ -0,0 +1,4 @@ +bindkey '^U' backward-kill-line +bindkey '^K' kill-line +bindkey '^Y' yank + diff --git a/zsh/lib/zplug.zsh b/zsh/lib/zplug.zsh new file mode 100644 index 0000000..7af5203 --- /dev/null +++ b/zsh/lib/zplug.zsh @@ -0,0 +1,51 @@ +if [ -e ${HOME}/.zplug/init.zsh ]; then + # For local manual installs + source ~/.zplug/init.zsh +elif [ -e /usr/share/zplug/init.zsh ]; then + # For system-wide installs + source /usr/share/zplug/init.zsh +elif [ -e /usr/local/opt/zplug/init.zsh ]; then + # For homebrew MacOSX + export ZPLUG_HOME=/usr/local/opt/zplug + source $ZPLUG_HOME/init.zsh +fi + +#zplug "zsh-users/zsh-completions" + +zplug "plugins/docker-compose", from:oh-my-zsh +zplug "plugins/kubectl", from:oh-my-zsh +zplug "plugins/git", from:oh-my-zsh +zplug "plugins/git-prompt", from:oh-my-zsh +zplug "lib/history", from:oh-my-zsh +zplug "plugins/sudo", from:oh-my-zsh +zplug "plugins/vi-mode", from:oh-my-zsh +zplug "plugins/vagrant", from:oh-my-zsh +zplug "lib/termsupport", from:oh-my-zsh + +# This has some inbuilt assumptions rather than straight aliases, for my use the omz version is better +#zplug "tcnksm/docker-alias", use:zshrc + +# I like the menus for command completion, I hate the history completion. +# zplug "marlonrichert/zsh-autocomplete", defer:2 +zplug "MichaelAquilina/zsh-autoswitch-virtualenv" +#zplug "jqlang/jq", from: + +zplug "b4b4r07/httpstat", as:command, use:'(*).sh', rename-to:'$1' +zplug "drwetter/testssl.sh", as:command, use:'(*).sh', rename-to:'$1' +#zplug "drwetter/testssl.sh", as:command, use: 'testssl.sh' + +#zplug "nichus/zsh-tmux-multisession" +zplug "nichus/zsh-todotxt", from:momodomo +zplug "nichus/qi3ber2", from:momodomo, as:theme + +zplug "zsh-users/zsh-syntax-highlighting", defer:2 +#zplug "zsh-users/zsh-history-substring-search", defer: 2 + +zplug "~/.zsh/plugins", from:local + +# In a world where I need zplug updates, this might be nice, but currently it isn't +#zplug "zplug/zplug", hook-build: "zplug --self-manage" + +zplug check || zplug install + +zplug load diff --git a/zsh/zshrc b/zsh/zshrc index e03695f..7645aab 100644 --- a/zsh/zshrc +++ b/zsh/zshrc @@ -5,40 +5,8 @@ export GPG_TTY=$(tty) export SSH_AUTH_SOCK=$(gpgconf --list-dirs agent-ssh-socket) #gpgconf --launch gpg-agent -# Settings for the *omz/lib/history* -# -# Set the timestamp format for history for ISO format -export HIST_STAMPS="yyyy-mm-dd" -# Don't bother storing these commands in history -export HISTORY_IGNORE="(ls|cd|cd -|pwd|exit|date|.* --help)" -# Set the location for the zsh_history file to be inside our .zsh foler -export HISTFILE="$ZDOTDIR/.zsh_history" -# Keep this many history events in per-shell memory -export HISTSIZE=100000 -# Keep this many history events in the log file -export SAVEHIST=50000 - export ZSH_TMUX_AUTOSTART=true -if [ -e ${HOME}/.zplug/init.zsh ]; then - # For local manual installs - source ~/.zplug/init.zsh -elif [ -e /usr/share/zplug/init.zsh ]; then - # For system-wide installs - source /usr/share/zplug/init.zsh -elif [ -e /usr/local/opt/zplug/init.zsh ]; then - # For homebrew MacOSX - export ZPLUG_HOME=/usr/local/opt/zplug - source $ZPLUG_HOME/init.zsh -fi - -alias pip=pip3 -alias vim="nvim" -alias vi="nvim" -alias vimdiff="nvim -d" -alias dlports="docker container ls --format table '{{.ID}}\t{{.Names}}\t{{.Ports}} -a'" -alias gpb=git-parent-branch - export EDITOR=nvim # Prefer case sensitive autocomplete export CASE_SENSITIVE="true" @@ -47,10 +15,8 @@ export AUTOSWITCH_DEFAULT_PYTHON=$(which python3) # My prompt reflects my venv automatically, don't pollute it by default export VIRTUAL_ENV_DISABLE_PROMPT=1 -# Use this to define the git lg alias -function define_gitlg { - git config --global alias.lg log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset' --abbrev-commit -} +source <(kubectl completion zsh) +source <(zoxide init zsh) # Code to maintain pagent connections to tmux through link drops #SOCK="/tmp/ssh-agent-$USER-tmux" @@ -60,56 +26,12 @@ function define_gitlg { # SSH_AUTH_SOCK=$SOCK #fi -#zplug "zsh-users/zsh-completions" -zplug "marlonrichert/zsh-autocomplete" +source "$ZDOTDIR/lib/zplug.zsh" -zplug "plugins/docker-compose", from:oh-my-zsh -zplug "plugins/git", from:oh-my-zsh -zplug "lib/history", from:oh-my-zsh -zplug "plugins/sudo", from:oh-my-zsh -zplug "plugins/vi-mode", from:oh-my-zsh -zplug "plugins/vagrant", from:oh-my-zsh -zplug "lib/termsupport", from:oh-my-zsh -zplug "tcnksm/docker-alias", use:zshrc +source "$ZDOTDIR/lib/aliases.zsh" +source "$ZDOTDIR/lib/autocomplete_overrides.zsh" +source "$ZDOTDIR/lib/git.zsh" +source "$ZDOTDIR/lib/history.zsh" # Source me _after_ zplug to override their defaults +source "$ZDOTDIR/lib/keybinds.zsh" -zplug "MichaelAquilina/zsh-autoswitch-virtualenv" -#zplug "jqlang/jq" - -zplug "b4b4r07/httpstat", as:command, use:'(*).sh', rename-to:'$1' -zplug "drwetter/testssl.sh", as:command, use:'(*).sh', rename-to:'$1' -#zplug "drwetter/testssl.sh", as:command, use: 'testssl.sh' - -#zplug "nichus/zsh-tmux-multisession" -zplug "nichus/zsh-todotxt" -zplug "nichus/qi3ber2", as:theme - -zplug "zsh-users/zsh-syntax-highlighting", defer:2 -zplug "zsh-users/zsh-history-substring-search", defer: 2 - -zplug "zplug/zplug", hook-build: "zplug --self-manage" - -zplug check || zplug install - -zplug load - -unsetopt share_history -unsetopt hist_verify -setopt hist_ignore_all_dups -setopt hist_find_no_dups - -source <(kubectl completion zsh) -eval "$(zoxide init zsh)" - -bindkey '^U' backward-kill-line -bindkey '^K' kill-line -bindkey '^Y' yank - -function git-parent-branch { - git show-branch -a \ - | grep '\*' \ - | grep -v `git-rev-parse --abbrev-ref HEAD` \ - | head -n1 \ - | sed 's/.*\[\(.*\)\].*/\1/' \ - | sed 's/[\^~].*//' -}