From 4fcd92157b2c247e0a4ef89c7ea803266d3a8277 Mon Sep 17 00:00:00 2001 From: Starfall Date: Mon, 29 Aug 2022 11:44:24 -0500 Subject: zsh: alias cat to bat, utils replacements to new file --- .config/zsh/.zshrc | 34 ++---------------------------- .config/zsh/completion.zsh | 17 +++++++++++++++ .config/zsh/completions.zsh | 17 --------------- .config/zsh/utils.zsh | 50 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 69 insertions(+), 49 deletions(-) create mode 100644 .config/zsh/completion.zsh delete mode 100644 .config/zsh/completions.zsh create mode 100644 .config/zsh/utils.zsh diff --git a/.config/zsh/.zshrc b/.config/zsh/.zshrc index 367794a..1766e57 100644 --- a/.config/zsh/.zshrc +++ b/.config/zsh/.zshrc @@ -13,28 +13,6 @@ export CDPATH=".:$HOME:$HOME/devil:$HOME/src" # just enables a bit nicer life when copy/pasting commands from docs setopt interactive_comments -# colors in various core utils -alias diff='diff --color' - -grep_opts="--color=auto --exclude-dir=.git" -alias grep="grep $grep_opts" -alias egrep="egrep $grep_opts" -alias fgrep="fgrep $grep_opts" -unset grep_opts - -if command -v exa &> /dev/null; then - alias ls='exa' - alias ll='exa --long --header --all' -elif ls --color &> /dev/null; then - # gnu ls - alias ls='ls --color=auto' - alias ll='ls -l --almost-all --no-group --human-readable' -else - # bsd/mac ls - export CLICOLOR='1' - alias ll='ls -hoA' -fi - # dots go up alias -g ...='../..' alias -g ....='../../..' @@ -43,15 +21,6 @@ alias -g .....='../../../..' # aliases alias cls=clear alias config='git --git-dir=$HOME/.dotfiles --work-tree=$HOME' -alias mkdir='mkdir -p' - -if command -v gpg2 &> /dev/null; then - alias gpg='gpg2' -fi - -if [[ "$OSTYPE" == 'cygwin' ]]; then - alias sudo='cygstart --action=runas' -fi # collapse spaces into tabs in-place # spacetotab [WIDTH=4] @@ -60,7 +29,8 @@ function spacetotab () { mv "$1.tmp" "$1" } -source $ZDOTDIR/completions.zsh +source $ZDOTDIR/utils.zsh +source $ZDOTDIR/completion.zsh source $ZDOTDIR/history.zsh source $ZDOTDIR/vi-mode.zsh source $ZDOTDIR/prompt.zsh diff --git a/.config/zsh/completion.zsh b/.config/zsh/completion.zsh new file mode 100644 index 0000000..bbaacba --- /dev/null +++ b/.config/zsh/completion.zsh @@ -0,0 +1,17 @@ +# completions +setopt complete_in_word # complete both ends of words +setopt always_to_end # and move cursor to the end afterward +setopt auto_menu # brings up the menu ... +setopt no_menu_complete # ... and does not select the first option +setopt auto_param_slash # convenience: add trailing / after directories +setopt no_case_glob +setopt no_flow_control +# complete . and .. +zstyle ':completion:*' special-dirs true +# complete the middle of words e.g. lc -> pluralcafe +zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|=*' 'l:|=* r:|=*' +# cache completions +zstyle ':completion::complete:*' use-cache yes +zstyle ':completion::complete:*' cache-path "$HOME/.zcompcache" +# enable completions +autoload -Uz compinit && compinit diff --git a/.config/zsh/completions.zsh b/.config/zsh/completions.zsh deleted file mode 100644 index bbaacba..0000000 --- a/.config/zsh/completions.zsh +++ /dev/null @@ -1,17 +0,0 @@ -# completions -setopt complete_in_word # complete both ends of words -setopt always_to_end # and move cursor to the end afterward -setopt auto_menu # brings up the menu ... -setopt no_menu_complete # ... and does not select the first option -setopt auto_param_slash # convenience: add trailing / after directories -setopt no_case_glob -setopt no_flow_control -# complete . and .. -zstyle ':completion:*' special-dirs true -# complete the middle of words e.g. lc -> pluralcafe -zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|=*' 'l:|=* r:|=*' -# cache completions -zstyle ':completion::complete:*' use-cache yes -zstyle ':completion::complete:*' cache-path "$HOME/.zcompcache" -# enable completions -autoload -Uz compinit && compinit diff --git a/.config/zsh/utils.zsh b/.config/zsh/utils.zsh new file mode 100644 index 0000000..e368ea0 --- /dev/null +++ b/.config/zsh/utils.zsh @@ -0,0 +1,50 @@ +# utils.zsh +# Replacements for coreutils, color and reasonable defaults for common tools, etc. + +function has () { + command -v "$@" &> /dev/null +} + +# cat +if has bat; then + alias cat='bat --plain --paging=never' +fi +# should consider another alias for --show-all (and --number on base cat) but it's not a good default + +# diff +alias diff='diff --color' + +# grep +grep_opts="--color=auto --exclude-dir=.git" +alias grep="grep $grep_opts" +alias egrep="egrep $grep_opts" +alias fgrep="fgrep $grep_opts" +unset grep_opts + +# ls +if has exa; then + alias ls='exa' + alias ll='exa --long --header --all' +elif ls --color &> /dev/null; then + alias ls='ls --color=auto' + alias ll='ls -l --almost-all --no-group --human-readable' +else + # bsd/mac ls + export CLICOLOR='1' + alias ll='ls -hoA' +fi + +# mkdir +alias mkdir='mkdir -p' + +# gpg +if has gpg2; then + alias gpg='gpg2' +fi + +# cygwin-specific +if [[ "$OSTYPE" == 'cygwin' ]]; then + alias sudo='cygstart --action=runas' +fi + +unfunction has -- cgit