aboutsummaryrefslogtreecommitdiff
path: root/config/all/zsh
diff options
context:
space:
mode:
Diffstat (limited to 'config/all/zsh')
-rw-r--r--config/all/zsh/.zprofile7
-rw-r--r--config/all/zsh/.zshrc4
-rw-r--r--config/all/zsh/20-appearance.zsh79
-rw-r--r--config/all/zsh/30-behavior.zsh54
-rw-r--r--config/all/zsh/40-key-bindings.zsh6
-rw-r--r--config/all/zsh/50-completion.zsh27
-rw-r--r--config/all/zsh/99-function-overrides.zsh8
7 files changed, 185 insertions, 0 deletions
diff --git a/config/all/zsh/.zprofile b/config/all/zsh/.zprofile
new file mode 100644
index 0000000..a9a13c9
--- /dev/null
+++ b/config/all/zsh/.zprofile
@@ -0,0 +1,7 @@
+if [ "$(uname)" = "Darwin" ]; then
+ # disable Apple Terminal's annoying session restore feature
+ SHELL_SESSIONS_DISABLE=1
+fi
+if [ "$DESKTOP_SESSION" = "sway-session" ]; then
+ export $(gnome-keyring-daemon --start)
+fi
diff --git a/config/all/zsh/.zshrc b/config/all/zsh/.zshrc
new file mode 100644
index 0000000..f33ca44
--- /dev/null
+++ b/config/all/zsh/.zshrc
@@ -0,0 +1,4 @@
+for f in $ZDOTDIR/*.zsh
+do
+ source "${f}"
+done
diff --git a/config/all/zsh/20-appearance.zsh b/config/all/zsh/20-appearance.zsh
new file mode 100644
index 0000000..4f7c8d9
--- /dev/null
+++ b/config/all/zsh/20-appearance.zsh
@@ -0,0 +1,79 @@
+#
+# colorize shell programs
+
+if ls -Z . &>/dev/null 2>&1; then
+ # gnu coreutils?
+ alias ls='ls --color=auto'
+ eval `dircolors ${XDG_CONFIG_HOME:-${HOME}/.config}/dircolors.conf`
+elif (( $+commands[gls] )); then
+ # prefixed gnu coreutils?
+ alias ls='gls --color=auto'
+ eval `gdircolors ${XDG_CONFIG_HOME:-${HOME}/.config}/dircolors.conf`
+else
+ # assume bsd ls
+ alias ls='ls -G'
+ export LSCOLORS="exgxbxdxcxegedxbxgxcxd"
+fi
+
+# grep
+export GREP_COLOR='1;32'
+alias grep='grep --color=auto'
+alias egrep='egrep --color=auto'
+alias fgrep='fgrep --color=auto'
+
+# less
+export LESS_TERMCAP_mb=$'\e[0;31m' # begin blinking - red
+export LESS_TERMCAP_md=$'\e[0;34m' # begin bold - blue
+export LESS_TERMCAP_me=$'\e[0m' # end mode
+export LESS_TERMCAP_so=$'\e[30;46m' # begin standout mode - black on cyan
+export LESS_TERMCAP_se=$'\e[0m' # end standout mode
+export LESS_TERMCAP_us=$'\e[4;33m' # begin underline - yellow underline
+export LESS_TERMCAP_ue=$'\e[0m' # end underline
+
+#
+# make a sweet prompt
+
+autoload colors; colors;
+setopt prompt_subst # expansion of color codes, etc. in the prompt
+
+# print the fully resolved shell command with time stamp
+# to be run from zsh's builtin 'preexec' with all arguments passed through ($*)
+function theme_preexec () {
+ echo "($fg[magenta]`date +%r`$reset_color) $fg[cyan]$3$reset_color"
+}
+
+# print the prompt char in red if the last command exited non-zero
+function prompt_char {
+ echo "%(?.$.%{$fg[red]%}$%{$reset_color%})"
+}
+
+function repo_prompt_info {
+ # git
+ ref=$(git symbolic-ref HEAD 2> /dev/null || git rev-parse --short HEAD 2> /dev/null)
+ if [ $? -eq 0 ]; then
+ #repo=$(basename $(git rev-parse --show-toplevel))
+ echo "%{$fg[cyan]%}%{\e[1m%}${ref#refs/heads/}%{$reset_color%}"
+ return
+ fi
+}
+
+function workspace_prompt_info {
+ repo=$(repo_prompt_info)
+ if [ "$repo" ]; then
+ echo "[$repo] "
+ return
+ fi
+}
+
+# print the hostname in green if local, else red
+function hostname_info {
+ if [[ $ZSH_LOCAL_ENV == "true" ]]; then
+ echo "%{$fg[green]%}%{$ZSH_HOST_PREFIX%}%m%{$ZSH_HOST_SUFFIX%}%{$reset_color%}"
+ else
+ echo "%{$fg[red]%}%{$ZSH_HOST_PREFIX%}%m%{$ZSH_HOST_SUFFIX%}%{$reset_color%}"
+ fi
+}
+
+# a colorful multiline prompt using the above defined functions
+PROMPT=$'%{$fg[yellow]%}%n%{$reset_color%}@$(hostname_info):%{$fg[blue]%}%~%{$reset_color%}
+$(workspace_prompt_info)$(prompt_char)%{$reset_color%} '
diff --git a/config/all/zsh/30-behavior.zsh b/config/all/zsh/30-behavior.zsh
new file mode 100644
index 0000000..6b2b2c2
--- /dev/null
+++ b/config/all/zsh/30-behavior.zsh
@@ -0,0 +1,54 @@
+#
+# execution
+
+setopt rm_star_wait # wait 10 seconds before accepting 'rm *' confirmation
+export REPORTTIME=5 # report timing for any command longer than 5 seconds
+unsetopt flowcontrol # disable ^s from freezing the terminal
+
+#
+# history
+
+HISTFILE="${XDG_DATA_HOME:-${HOME}/.local/share}/zsh/history"
+HISTSIZE=10000
+SAVEHIST=10000
+
+setopt hist_ignore_all_dups # ignore dups including non-sequential ones
+setopt share_history # share command history data between sessions
+setopt hist_verify # load hist into command buffer rather than exec immediately
+
+#
+# term support
+
+# make sure $TERM is installed
+# if not, fall back on xterm-256color
+infocmp "$TERM" > /dev/null 2>&1 || export TERM=xterm-256color
+
+# set term title appropriately based on term type
+# user@host:current_dir (current_command)
+case "$TERM" in
+ xterm*|rxvt*|screen*|alacritty*|foot)
+ term_preexec () {
+ printf '\e]0;%s (%s)\a' ${(%):-'%n@%m:%~'} "$1"
+ }
+ term_precmd () {
+ printf '\e]0;%s\a' ${(%):-'%n@%m:%~'}
+ }
+ ;;
+esac
+
+#
+# draw a horizontal separator
+
+function hr {
+ printf "$bg[red]${(l:$COLUMNS:: :)}$reset_color\n"
+ printf "$bg[yellow]${(l:$COLUMNS:: :)}\n"
+ printf "$bg[green]${(l:$COLUMNS:: :)}\n"
+ printf "$bg[cyan]${(l:$COLUMNS:: :)}\n"
+ printf "$bg[blue]${(l:$COLUMNS:: :)}\n"
+ printf "$bg[magenta]${(l:$COLUMNS:: :)}$reset_color\n"
+}
+
+#
+# less
+
+export LESS=-i
diff --git a/config/all/zsh/40-key-bindings.zsh b/config/all/zsh/40-key-bindings.zsh
new file mode 100644
index 0000000..4deac62
--- /dev/null
+++ b/config/all/zsh/40-key-bindings.zsh
@@ -0,0 +1,6 @@
+bindkey -e # use emacs mode
+bindkey '^r' history-incremental-search-backward # ctrl-r
+bindkey '^[[Z' reverse-menu-complete # shift-tab
+
+bindkey '\e[3~' delete-char # make sure delete key works
+bindkey ' ' magic-space # also do history expansion on space
diff --git a/config/all/zsh/50-completion.zsh b/config/all/zsh/50-completion.zsh
new file mode 100644
index 0000000..23cb052
--- /dev/null
+++ b/config/all/zsh/50-completion.zsh
@@ -0,0 +1,27 @@
+# initialize the completion system
+autoload -U compinit
+compinit -d "${XDG_CACHE_HOME:-${HOME}/.cache}/zsh/zcompdump"
+zmodload zsh/complist
+
+# complete only after the second consecutive tab
+setopt auto_menu
+
+# use GNU ls color specification for completion menu
+zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
+
+# use menu selection by default
+zstyle ':completion:*:default' menu select
+
+# disable named-directories autocompletion
+zstyle ':completion:*:cd:*' tag-order local-directories directory-stack path-directories
+cdpath=(.)
+
+# don't autocomplete local users for (ssh|ftp|scp|rsync)
+zstyle ':completion:*:*:(ssh|ftp|scp|rsync):*' users
+
+# Use caching so that commands like apt and dpkg complete are useable
+zstyle ':completion::complete:*' use-cache 1
+zstyle ':completion:*' cache-path "${XDG_CACHE_HOME:-${HOME}/.cache}/zsh/zcompcache"
+
+# always rehash commands list
+zstyle ':completion:*:commands' rehash 1
diff --git a/config/all/zsh/99-function-overrides.zsh b/config/all/zsh/99-function-overrides.zsh
new file mode 100644
index 0000000..8b233e5
--- /dev/null
+++ b/config/all/zsh/99-function-overrides.zsh
@@ -0,0 +1,8 @@
+preexec () {
+ type term_preexec &> /dev/null && term_preexec $*
+ type theme_preexec &> /dev/null && theme_preexec $*
+}
+
+precmd () {
+ type term_precmd &> /dev/null && term_precmd
+}