feat: initial framework
This commit is contained in:
parent
be765357d5
commit
d44dd103a3
14 changed files with 355 additions and 0 deletions
10
completions/_autosource
Normal file
10
completions/_autosource
Normal file
|
@ -0,0 +1,10 @@
|
|||
#compdef autosource
|
||||
|
||||
_autosource() {
|
||||
_alternative \
|
||||
'plugin:filename:{_path_files -W spath}'
|
||||
}
|
||||
|
||||
_autosource
|
||||
|
||||
# vim: ft=zsh expandtab tabstop=2 shiftwidth=2
|
11
functions/autosource
Normal file
11
functions/autosource
Normal file
|
@ -0,0 +1,11 @@
|
|||
#!/bin/zsh
|
||||
local f=
|
||||
local p=
|
||||
|
||||
for f; do
|
||||
for p in $spath; do
|
||||
[[ -r $p/$f ]] && . "$p/$f" && break
|
||||
done
|
||||
done
|
||||
|
||||
# vim: ft=zsh expandtab tabstop=2 shiftwidth=2
|
17
functions/sourceall
Normal file
17
functions/sourceall
Normal file
|
@ -0,0 +1,17 @@
|
|||
#!/bin/zsh
|
||||
# usage:
|
||||
# `sourceall zsh` will source *.zsh, otherwise *
|
||||
|
||||
local ext=
|
||||
local f=
|
||||
local p=
|
||||
|
||||
(( $# > 0 )) && ext=".$1"
|
||||
for p in $apath; do
|
||||
[[ -d $p ]] || continue
|
||||
for f in $p/*$ext(.N); do
|
||||
[[ -r $f ]] && . $f
|
||||
done
|
||||
done
|
||||
|
||||
# vim: ft=zsh expandtab tabstop=2 shiftwidth=2
|
13
plugins/coloured-man
Normal file
13
plugins/coloured-man
Normal file
|
@ -0,0 +1,13 @@
|
|||
# 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 "$@"
|
||||
}
|
||||
|
||||
# vim: ft=zsh expandtab tabstop=2 shiftwidth=2
|
21
plugins/sudo
Normal file
21
plugins/sudo
Normal file
|
@ -0,0 +1,21 @@
|
|||
# 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
|
||||
}
|
||||
|
||||
zle -N sudo-command-line
|
||||
# defined shortcut keys: [Esc] [Esc]
|
||||
bindkey "\e\e" sudo-command-line
|
||||
|
||||
# vim: ft=zsh expandtab tabstop=2 shiftwidth=2
|
74
source/aliases.zsh
Normal file
74
source/aliases.zsh
Normal file
|
@ -0,0 +1,74 @@
|
|||
# common aliases
|
||||
alias grep='grep --color=auto'
|
||||
alias diff='diff --color=auto'
|
||||
alias history='fc -il 1' # redirect history to STDOUT with correct timestamps
|
||||
|
||||
# safe(r) interactive commands
|
||||
alias rm='rm -i'
|
||||
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'
|
||||
|
||||
# directories
|
||||
setopt AUTO_CD # prefix command with 'cd' if it cannot be executed, e.g. '..' becomes 'cd ..'
|
||||
alias ...='../..'
|
||||
alias ....='../../..'
|
||||
alias .....='../../../..'
|
||||
alias ......='../../../../..'
|
||||
|
||||
# git
|
||||
if command -v git &> /dev/null; then
|
||||
# status
|
||||
alias gst='git status'
|
||||
|
||||
# add/commit
|
||||
alias gaa='git add --all'
|
||||
alias gcmsg='git commit -m'
|
||||
|
||||
# log
|
||||
alias glg='git log --stat'
|
||||
alias glgp='git log --stat -p'
|
||||
alias glgg='git log --graph'
|
||||
alias glgga='git log --graph --decorate --all'
|
||||
alias glgm='git log --graph --max-count=10'
|
||||
|
||||
# push/pull
|
||||
alias gp='git push'
|
||||
alias gl='git pull'
|
||||
fi
|
||||
|
||||
# pacman
|
||||
if command -v pacman &> /dev/null; then
|
||||
# source: https://wiki.archlinux.org/index.php/Pacman_Tips
|
||||
alias pacupg='sudo pacman -Syu'
|
||||
alias pacin='sudo pacman -S'
|
||||
alias pacins='sudo pacman -U'
|
||||
alias pacre='sudo pacman -R'
|
||||
alias pacrem='sudo pacman -Rns'
|
||||
alias pacrep='pacman -Si'
|
||||
alias pacreps='pacman -Ss'
|
||||
alias pacloc='pacman -Qi'
|
||||
alias paclocs='pacman -Qs'
|
||||
alias pacinsd='sudo pacman -S --asdeps'
|
||||
alias pacmir='sudo pacman -Syy'
|
||||
alias paclsorphans='sudo pacman -Qdt'
|
||||
alias pacrmorphans='sudo pacman -Rs $(pacman -Qtdq)'
|
||||
alias pacfileupg='sudo pacman -Fy'
|
||||
alias pacfiles='pacman tFs'
|
||||
|
||||
# list all explicitly installed packages
|
||||
# source: https://bbs.archlinux.org/viewtopic.php?id=93683
|
||||
paclist() {
|
||||
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
|
48
source/bindkeys.zsh
Normal file
48
source/bindkeys.zsh
Normal file
|
@ -0,0 +1,48 @@
|
|||
# key bindings
|
||||
|
||||
# create a zkbd compatible hash;
|
||||
# to add other keys to this hash, see: man 5 terminfo
|
||||
typeset -g -A key
|
||||
|
||||
#key[Home]="${terminfo[khome]}"
|
||||
#key[End]="${terminfo[kend]}"
|
||||
#key[Insert]="${terminfo[kich1]}"
|
||||
key[Backspace]="${terminfo[kbs]}"
|
||||
key[Delete]="${terminfo[kdch1]}"
|
||||
key[Up]="${terminfo[kcuu1]}"
|
||||
key[Down]="${terminfo[kcud1]}"
|
||||
key[Left]="${terminfo[kcub1]}"
|
||||
key[Right]="${terminfo[kcuf1]}"
|
||||
key[PageUp]="${terminfo[kpp]}"
|
||||
key[PageDown]="${terminfo[knp]}"
|
||||
key[ShiftTab]="${terminfo[kcbt]}"
|
||||
|
||||
# setup history search
|
||||
autoload -Uz up-line-or-beginning-search down-line-or-beginning-search
|
||||
zle -N up-line-or-beginning-search
|
||||
zle -N down-line-or-beginning-search
|
||||
|
||||
# key bindings
|
||||
[[ -n "${key[Backspace]}" ]] && bindkey -- "${key[Backspace]}" backward-delete-char
|
||||
[[ -n "${key[Delete]}" ]] && bindkey -- "${key[Delete]}" delete-char
|
||||
[[ -n "${key[Up]}" ]] && bindkey -- "${key[Up]}" up-line-or-beginning-search
|
||||
[[ -n "${key[Down]}" ]] && bindkey -- "${key[Down]}" 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
|
||||
|
||||
# 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() {
|
||||
echoti smkx
|
||||
}
|
||||
zle_application_mode_stop() {
|
||||
echoti rmkx
|
||||
}
|
||||
add-zle-hook-widget -Uz zle-line-init zle_application_mode_start
|
||||
add-zle-hook-widget -Uz zle-line-finish zle_application_mode_stop
|
||||
fi
|
||||
|
||||
# vim: ft=zsh expandtab tabstop=2 shiftwidth=2
|
15
source/colours.zsh
Normal file
15
source/colours.zsh
Normal file
|
@ -0,0 +1,15 @@
|
|||
#
|
||||
# colours
|
||||
#
|
||||
|
||||
autoload -U colors && colors
|
||||
|
||||
# setup LS_COLORS
|
||||
if [[ -z "$LS_COLORS" ]]; then
|
||||
(( $+commands[dircolors] )) && eval "$(dircolors -b)"
|
||||
fi
|
||||
|
||||
# use LS_COLORS for completion
|
||||
zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}"
|
||||
|
||||
# vim: ft=zsh expandtab tabstop=2 shiftwidth=2
|
25
source/completions.zsh
Normal file
25
source/completions.zsh
Normal file
|
@ -0,0 +1,25 @@
|
|||
# completion configuration
|
||||
|
||||
# have the menu highlight as we cycle through options
|
||||
zstyle ':completion:*' menu select
|
||||
# case insensitive (all), partial-word and substring completion
|
||||
zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|=*' 'l:|=* r:|=*'
|
||||
# allow completion from within a word/phrase
|
||||
setopt COMPLETE_IN_WORD
|
||||
# when completing from the middle of a word, move cursor to end of word
|
||||
setopt ALWAYS_TO_END
|
||||
# turn on completion for aliases as well
|
||||
setopt COMPLETE_ALIASES
|
||||
# cycle through menus horizontally instead of vertically
|
||||
#setopt LIST_ROWS_FIRST
|
||||
# when using auto-complete, put the first option on the line immediately
|
||||
#setopt MENU_COMPLETE
|
||||
|
||||
# complete . and .. special directories
|
||||
zstyle ':completion:*' special-dirs true
|
||||
|
||||
# use caching so that commands like apt and dpkg complete are useable
|
||||
zstyle ':completion::complete:*' use-cache 1
|
||||
zstyle ':completion::complete:*' cache-path "{$ZCACHEDIR}"
|
||||
|
||||
# vim: ft=zsh expandtab tabstop=2 shiftwidth=2
|
13
source/env.zsh
Normal file
13
source/env.zsh
Normal file
|
@ -0,0 +1,13 @@
|
|||
# locale [en_NZ]
|
||||
export LANG='en_NZ.UTF-8'
|
||||
export LC_ALL='en_NZ.UTF-8'
|
||||
|
||||
# set default values
|
||||
export EDITOR='nvim'
|
||||
export PAGER='less'
|
||||
export LESS='-R'
|
||||
|
||||
# less - disable histfile generation
|
||||
export LESSHISTFILE='/dev/null'
|
||||
|
||||
# vim: ft=zsh expandtab tabstop=2 shiftwidth=2
|
15
source/gpg.zsh
Normal file
15
source/gpg.zsh
Normal file
|
@ -0,0 +1,15 @@
|
|||
# From gpg-agent(1):
|
||||
#
|
||||
# You should always add the following lines to your .bashrc or whatever
|
||||
# initialization file is used for all shell invocations:
|
||||
#
|
||||
# GPG_TTY=$(tty)
|
||||
# export GPG_TTY
|
||||
#
|
||||
# It is important that this environment variable always reflects the out‐
|
||||
# put of the tty command.
|
||||
|
||||
GPG_TTY=$(tty)
|
||||
export GPG_TTY
|
||||
|
||||
# vim: ft=zsh expandtab tabstop=2 shiftwidth=2
|
27
source/options.zsh
Normal file
27
source/options.zsh
Normal file
|
@ -0,0 +1,27 @@
|
|||
# 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
|
||||
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
|
||||
|
||||
# create history file
|
||||
[ -z "${HISTFILE}" ] && HISTFILE="${ZCACHEDIR}/zhistory"
|
12
zshenv
Normal file
12
zshenv
Normal file
|
@ -0,0 +1,12 @@
|
|||
# set environment variable $ZDOTDIR to $HOME/.config/zsh
|
||||
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
|
||||
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
|
||||
|
||||
# vim: ft=zsh expandtab tabstop=2 shiftwidth=2
|
54
zshrc
Normal file
54
zshrc
Normal file
|
@ -0,0 +1,54 @@
|
|||
# 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
|
||||
|
||||
# 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
|
||||
fpath+=(
|
||||
"$ZDOTDIR/functions"
|
||||
"$ZDOTDIR/completions"
|
||||
"$ZDOTDIR/prompts"
|
||||
"$ZSYSDIR/functions"
|
||||
"$ZSYSDIR/completions"
|
||||
"$ZSYSDIR/prompts"
|
||||
)
|
||||
|
||||
# source every zsh file in every APATH directory
|
||||
autoload sourceall
|
||||
sourceall zsh
|
||||
|
||||
# plugins
|
||||
autoload autosource
|
||||
autosource coloured-man
|
||||
autosource sudo
|
||||
|
||||
# setup ys prompt
|
||||
autoload -Uz promptinit && promptinit
|
||||
prompt ys
|
||||
|
||||
# source local zshrc
|
||||
[[ -f "$ZDOTDIR/zshrc.local" ]] && . "$ZDOTDIR/zshrc.local"
|
||||
|
||||
# setup compinit
|
||||
autoload -U compinit
|
||||
compinit -i -d "${ZCACHEDIR}/zcompdump-${ZSH_VERSION}"
|
||||
|
||||
# vim: ft=zsh expandtab tabstop=2 shiftwidth=2
|
Loading…
Reference in a new issue