Compare commits

...

23 Commits

Author SHA1 Message Date
George Rawlinson 33ce3aa836
feat(plugin): add rust 2021-08-22 19:14:37 +12:00
George Rawlinson 9f3b8c5de8
feat(plugin): add ruby 2021-08-22 19:14:23 +12:00
George Rawlinson 9cf5287c49
feat(plugin): add pyenv 2021-08-22 19:14:08 +12:00
George Rawlinson 75fb0068a0
feat(plugin): add npm 2021-08-22 19:13:56 +12:00
George Rawlinson f6002e0668
feat: add support for xdg directories 2021-08-22 07:13:21 +00:00
George Rawlinson a3f9c9f462
refactor: colourise ls based on operating system
Use different method for coloured ls on macOS & Linux.
2021-07-08 17:16:54 +00:00
George Rawlinson 63dc963b00
fix: remove colourised aliases for grep/diff 2021-07-08 17:15:51 +00:00
George Rawlinson e6776b9564
fix: remove environment variable from aliases file 2021-07-08 17:03:23 +00:00
George Rawlinson 1975a585c0
refactor: colourise man based on operating system
Use different method for coloured man on macOS & Linux.
2021-07-08 16:57:44 +00:00
George Rawlinson f3ae58d3eb
chore: whitespace changes 2021-07-08 16:52:07 +00:00
George Rawlinson 9061406734
refactor: group relevant sections in zshrc 2021-07-08 16:51:12 +00:00
George Rawlinson 29a2860649
docs: simplify zshenv comments 2021-07-08 16:47:22 +00:00
George Rawlinson 51e5d74b70
fix: simplify sudo plugin
sudoedit isn't available on all systems.
sometimes we don't want to use $EDITOR. or it is not set.
2021-07-08 16:29:42 +00:00
George Rawlinson 2688ff59a1
fix: remove opinionated environment variables
* LANG
* LC_ALL
* EDITOR
2021-07-08 15:43:43 +00:00
George Rawlinson a9bec11e31
fix: only export GPG_TTY if gpg is installed 2021-07-08 14:33:48 +00:00
George Rawlinson 7b205e5b2b
fix: incorrect cache path 2019-12-05 20:19:39 +13:00
George Rawlinson 3dd89cd9bf
feat(zsh): create user zshrc if it doesn't exist 2019-12-05 20:17:53 +13:00
George Rawlinson 6157aa7c2c
feat(options): remove unused settings 2019-11-05 19:20:39 +13:00
George Rawlinson fb2394591b
docs(bindkeys): copy comment from arch wiki's zsh page 2019-11-05 19:19:52 +13:00
George Rawlinson 04f520aa1d
feat(bindkeys): set emacs mode 2019-11-05 19:18:59 +13:00
George Rawlinson 42663a579e
feat(bindkeys): add {for,back}ward word 2019-11-05 19:18:11 +13:00
George Rawlinson 385527ed4c
feat: add git diff aliases 2019-11-05 16:02:18 +13:00
George Rawlinson 5389285e02
docs(license): add original author 2019-11-01 22:24:22 +13:00
16 changed files with 203 additions and 77 deletions

View File

@ -1,5 +1,6 @@
The MIT License (MIT)
Copyright (c) 2017 Chloe Kudryavtsev
Copyright (c) 2019 George Rawlinson <mailto:george@rawlinson.net.nz>
Permission is hereby granted, free of charge, to any person obtaining a copy

View File

@ -1,13 +1,23 @@
# colour output in man
# source: https://wiki.archlinux.org/index.php/Color_output_in_console#man
man() {
LESS_TERMCAP_md=$'\e[01;31m' \
LESS_TERMCAP_me=$'\e[0m' \
LESS_TERMCAP_se=$'\e[0m' \
LESS_TERMCAP_so=$'\e[01;44;33m' \
LESS_TERMCAP_ue=$'\e[0m' \
LESS_TERMCAP_us=$'\e[01;32m' \
command man "$@"
}
#
# coloured-man
#
# https://wiki.archlinux.org/index.php/Color_output_in_console#man
if [[ -v OSTYPE ]]; then
if [[ "$OSTYPE" == "linux"* ]]; then
export MANPAGER="less -R --use-color -Dd+r -Du+b"
elif [[ "$OSTYPE" == "darwin"* ]]; then
man() {
LESS_TERMCAP_md=$'\e[01;31m' \
LESS_TERMCAP_me=$'\e[0m' \
LESS_TERMCAP_se=$'\e[0m' \
LESS_TERMCAP_so=$'\e[01;44;33m' \
LESS_TERMCAP_ue=$'\e[0m' \
LESS_TERMCAP_us=$'\e[01;32m' \
command man "$@"
}
fi
fi
# vim: ft=zsh expandtab tabstop=2 shiftwidth=2

24
plugins/npm Normal file
View File

@ -0,0 +1,24 @@
#
# npm
#
# Install NPM packages globally without requiring sudo
# https://github.com/sindresorhus/guides/blob/master/npm-global-without-sudo.md
if command -v npm &> /dev/null; then
# Use XDG dirs
export NPM_CONFIG_USERCONFIG="$XDG_CONFIG_HOME/npm/config"
export NPM_CONFIG_CACHE="$XDG_CACHE_HOME/npm"
export NPM_CONFIG_TMP="$XDG_RUNTIME_DIR/npm"
export NPM_CONFIG_PREFIX="$XDG_DATA_HOME/npm"
# add npm binary directory to PATH
path+=("$NPM_CONFIG_PREFIX/bin")
export PATH
# Rare, but some npm packages install man pages...
MANPATH="$NPM_CONFIG_PREFIX/share/man:$(manpath)"
export MANPATH
fi
# vim: ft=zsh expandtab tabstop=2 shiftwidth=2

12
plugins/pyenv Normal file
View File

@ -0,0 +1,12 @@
#
# pyenv
#
# Add pyenv binary directory to PATH
if command -v pyenv &> /dev/null; then
export PYENV_ROOT="$HOME/.cache/pyenv"
PATH="$PYENV_ROOT/shims:$PYENV_ROOT/bin:$PATH"
export PATH
fi
# vim: ft=zsh expandtab tabstop=2 shiftwidth=2

11
plugins/ruby Normal file
View File

@ -0,0 +1,11 @@
#
# ruby
#
# Add rubygem binary directory to PATH
if command -v ruby &> /dev/null; then
path+=("$(ruby -e "puts Gem.user_dir")/bin")
export PATH
fi
# vim: ft=zsh expandtab tabstop=2 shiftwidth=2

16
plugins/rust Normal file
View File

@ -0,0 +1,16 @@
#
# rust
#
# Add Cargo binary directory to PATH
if command -v cargo &> /dev/null; then
# set CARGO_HOME if not set
if [ -z "${CARGO_HOME}" ]; then
export CARGO_HOME="$HOME/.cargo"
fi
path+=("$CARGO_HOME/bin")
export PATH
fi
# vim: ft=zsh expandtab tabstop=2 shiftwidth=2

View File

@ -1,14 +1,11 @@
#
# sudo will be inserted before the current command
#
sudo-command-line() {
[[ -z $BUFFER ]] && zle up-history
if [[ $BUFFER == sudo\ * ]]; then
LBUFFER="${LBUFFER#sudo }"
elif [[ $BUFFER == $EDITOR\ * ]]; then
LBUFFER="${LBUFFER#$EDITOR }"
LBUFFER="sudoedit $LBUFFER"
elif [[ $BUFFER == sudoedit\ * ]]; then
LBUFFER="${LBUFFER#sudoedit }"
LBUFFER="$EDITOR $LBUFFER"
else
LBUFFER="sudo $LBUFFER"
fi

View File

@ -1,7 +1,9 @@
# common aliases
alias grep='grep --color=auto'
alias diff='diff --color=auto'
alias history='fc -il 1' # redirect history to STDOUT with correct timestamps
#
# aliases
#
# redirect history to STDOUT with correct timestamps
alias history='fc -il 1'
# safe(r) interactive commands
alias rm='rm -i'
@ -9,10 +11,21 @@ alias cp='cp -i'
alias mv='mv -i'
# ls
alias ls='ls --color=auto --human-readable --group-directories-first'
alias l='ls --classify -l'
alias la='ls --classify -la'
alias lr='ls --classify -tR'
if [[ -v OSTYPE ]]; then
if [[ "$OSTYPE" == "linux"* ]]; then
alias ls='ls --color=auto --human-readable --group-directories-first'
elif [[ "$OSTYPE" == "darwin"* ]]; then
# check for coreutils presence, otherwise we're using bsd ls
if command -v gls &> /dev/null; then
alias ls='gls --color=auto --human-readable --group-directories-first'
else
alias ls='ls -G'
fi
fi
fi
alias l='ls -l'
alias la='ls -la'
alias lr='ls -lR'
# directories
setopt AUTO_CD # prefix command with 'cd' if it cannot be executed, e.g. '..' becomes 'cd ..'
@ -40,6 +53,10 @@ if command -v git &> /dev/null; then
# push/pull
alias gp='git push'
alias gl='git pull'
# diff
alias gd='git diff'
alias gdca='git diff --cached'
fi
# pacman
@ -67,8 +84,6 @@ if command -v pacman &> /dev/null; then
LC_ALL=C pacman -Qei $(pacman -Qu | cut -d " " -f 1) | \
awk 'BEGIN {FS=":"} /^Name/{printf("\033[1;36m%s\033[1;37m", $2)} /^Description/{print $2}'
}
export CHROOT="${XDG_CACHE_HOME}/chroot"
fi
# vim: ft=zsh expandtab tabstop=2 shiftwidth=2

View File

@ -1,4 +1,9 @@
#
# key bindings
#
# set emacs mode
bindkey -e
# create a zkbd compatible hash;
# to add other keys to this hash, see: man 5 terminfo
@ -30,9 +35,12 @@ zle -N down-line-or-beginning-search
[[ -n "${key[PageUp]}" ]] && bindkey -- "${key[PageUp]}" up-line-or-history
[[ -n "${key[PageDown]}" ]] && bindkey -- "${key[PageDown]}" down-line-or-history
[[ -n "${key[ShiftTab]}" ]] && bindkey -- "${key[ShiftTab]}" reverse-menu-complete
bindkey '^[[1;5C' forward-word # [Ctrl-RightArrow] - move forward one word
bindkey '^[[1;5D' backward-word # [Ctrl-LeftArrow] - move backward one word
# make sure the terminal is in application mode when zle is active
# only then are the values from $terminfo valid
# Finally, make sure the terminal is in application mode, when zle is
# active. Only then are the values from $terminfo valid.
if (( ${+terminfo[smkx]} && ${+terminfo[rmkx]} )); then
autoload -Uz add-zle-hook-widget
zle_application_mode_start() {

View File

@ -1,4 +1,6 @@
#
# completion configuration
#
# have the menu highlight as we cycle through options
zstyle ':completion:*' menu select
@ -18,8 +20,8 @@ setopt COMPLETE_ALIASES
# complete . and .. special directories
zstyle ':completion:*' special-dirs true
# use caching so that commands like apt and dpkg complete are useable
# enable caching so that commands like apt and dpkg are completeable
zstyle ':completion::complete:*' use-cache 1
zstyle ':completion::complete:*' cache-path "{$ZCACHEDIR}"
zstyle ':completion::complete:*' cache-path "${ZCACHEDIR}"
# vim: ft=zsh expandtab tabstop=2 shiftwidth=2

View File

@ -1,13 +1,12 @@
# locale [en_NZ]
export LANG='en_NZ.UTF-8'
export LC_ALL='en_NZ.UTF-8'
#
# environment variables
#
# set default values
export EDITOR='nvim'
# set default pager
export PAGER='less'
export LESS='-R'
# less - disable histfile generation
# ensure less does not generate history file
export LESSHISTFILE='/dev/null'
# vim: ft=zsh expandtab tabstop=2 shiftwidth=2

View File

@ -9,7 +9,9 @@
# It is important that this environment variable always reflects the out
# put of the tty command.
GPG_TTY=$(tty)
export GPG_TTY
if command -v gpg-agent &> /dev/null; then
GPG_TTY=$(tty)
export GPG_TTY
fi
# vim: ft=zsh expandtab tabstop=2 shiftwidth=2

View File

@ -1,9 +1,11 @@
#
# zsh-specific options
#
# general
setopt NO_BEEP # disable terminal beep
setopt MULTI_OS # pipe to multiple outputs
setopt INTERACTIVE_COMMENTS # allow comments in interactive shell
setopt VI # vi-like keybindings
#setopt KSH_ARRAYS # whoever thought non-0 indices needs to be shot
# globbing
setopt NO_CASE_GLOB # case insensitive globbing
@ -11,17 +13,17 @@ setopt EXTENDED_GLOB # enable zsh globbing features
setopt NUMERIC_GLOB_SORT # sort globs numerically, not by letter
# history
HISTSIZE=100000 # set history size to 100K
SAVEHIST="${HISTSIZE}" # cap history size at 100K
setopt EXTENDED_HISTORY # record timestamp on command in HISTFILE
setopt HIST_EXPIRE_DUPS_FIRST # delete duplicates first when HISTFILE > HISTSIZE
setopt APPEND_HISTORY # ignore duplicate commands in history list
setopt HIST_FIND_NO_DUPS # when searching history don't display results already cycled through twice
setopt HIST_IGNORE_SPACE # ignore commands that start with space
setopt HIST_VERIFY # show command with history expansion to user before running it
setopt SHARE_HISTORY # shares history across multiple zsh sessions, in real time
setopt HIST_IGNORE_ALL_DUPS # do not write commands to history that are duplicates of the previous command
setopt HIST_REDUCE_BLANKS # remove erroneous blanks from commands before appending to history
HISTSIZE=100000 # set history size to 100K
SAVEHIST="${HISTSIZE}" # cap history size at 100K
setopt EXTENDED_HISTORY # record timestamp on command in HISTFILE
setopt HIST_EXPIRE_DUPS_FIRST # delete duplicates first when HISTFILE > HISTSIZE
setopt APPEND_HISTORY # ignore duplicate commands in history list
setopt HIST_FIND_NO_DUPS # when searching history don't display results already cycled through twice
setopt HIST_IGNORE_SPACE # ignore commands that start with space
setopt HIST_VERIFY # show command with history expansion to user before running it
setopt SHARE_HISTORY # shares history across multiple zsh sessions, in real time
setopt HIST_IGNORE_ALL_DUPS # do not write commands to history that are duplicates of the previous command
setopt HIST_REDUCE_BLANKS # remove erroneous blanks from commands before appending to history
# create history file
[ -z "${HISTFILE}" ] && HISTFILE="${ZCACHEDIR}/zhistory"

28
source/xdg.zsh Normal file
View File

@ -0,0 +1,28 @@
#
# xdg base directory variables
#
# https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
if [ -z "${XDG_CONFIG_HOME}" ]; then
export XDG_CONFIG_HOME="${HOME}/.config"
fi
if [ -z "${XDG_CACHE_HOME}" ]; then
export XDG_CACHE_HOME="${HOME}/.cache"
fi
if [ -z "${XDG_DATA_HOME}" ]; then
export XDG_DATA_HOME="${HOME}/.local/share"
fi
if [ -z "${XDG_STATE_HOME}" ]; then
export XDG_STATE_HOME="${HOME}/.local/state"
fi
# XDG_RUNTIME_DIR is set when using pam_systemd
if [[ "$OSTYPE" == "darwin"* ]]; then
export XDG_RUNTIME_DIR=/tmp
fi
# vim: ft=zsh expandtab tabstop=2 shiftwidth=2

9
zshenv
View File

@ -1,12 +1,15 @@
# set environment variable $ZDOTDIR to $HOME/.config/zsh
# set environment variables to conform with XDG base directory specification
export ZDOTDIR="${HOME}/.config/zsh"
# set environment variable $ZCACHEDIR to $HOME/.cache/zsh
export ZCACHEDIR="${HOME}/.cache/zsh"
# set environment variable $ZSYSDIR to /usr/share/zsh-grawlinson
# set framework location
export ZSYSDIR="/usr/share/zsh-grawlinson"
# create missing folders
if [ ! -d "${ZDOTDIR}" ]; then mkdir -p "${ZDOTDIR}"; fi
if [ ! -d "${ZCACHEDIR}" ]; then mkdir -p "${ZCACHEDIR}"; fi
# create empty zshrc if it does not exist
if [ ! -e "${ZDOTDIR}/.zshrc" ]; then touch "${ZDOTDIR}/.zshrc"; fi
# vim: ft=zsh expandtab tabstop=2 shiftwidth=2

40
zshrc
View File

@ -1,27 +1,11 @@
# setup umask [0755]
umask 0022
# spath -> plugins; apath -> drop-in path
typeset -T SPATH spath
typeset -T APATH apath
typeset -U PATH path # discard duplicates
# ensure there are no duplicates in $PATH
typeset -U PATH path
# example: append to path, then make available to child processes
# path+=('$VAR'); export PATH
# default path values
spath=(
"$ZDOTDIR/plugins"
"$ZSYSDIR/plugins"
)
apath=(
"$ZDOTDIR/source"
"$ZSYSDIR/source"
)
# user stuff comes first
# completions come after the functions they complete
# user files sourced before system files
# completions sourced after the functions they complete
fpath+=(
"$ZDOTDIR/functions"
"$ZDOTDIR/completions"
@ -31,11 +15,23 @@ fpath+=(
"$ZSYSDIR/prompts"
)
# source every zsh file in every APATH directory
# drop-in directory (like /etc/zsh.d)
# sourceall iterates over APATH, sourcing every file it finds
typeset -T APATH apath
apath=(
"$ZDOTDIR/source"
"$ZSYSDIR/source"
)
autoload sourceall
sourceall zsh
# plugins
# plugins (explicitly loaded)
# autosource iterates over SPATH until a matching plugin is found and sourced
typeset -T SPATH spath
spath=(
"$ZDOTDIR/plugins"
"$ZSYSDIR/plugins"
)
autoload autosource
autosource coloured-man
autosource sudo