From 3a62391e0e3311909ea8fec5a3d32001dc35f360 Mon Sep 17 00:00:00 2001 From: Matt Hamilton Date: Tue, 15 Dec 2015 00:12:17 -0500 Subject: [PATCH] initial commit --- .gitignore | 2 + .gitmodules | 9 + README.md | 57 ++++++ init.zsh | 47 +++++ modules/completion/external | 1 + modules/completion/init.zsh | 108 ++++++++++ modules/directory/init.zsh | 38 ++++ modules/environment/init.zsh | 28 +++ modules/git/alias.zsh | 184 ++++++++++++++++++ modules/git/functions/git-branch-current | 20 ++ modules/git/functions/git-commit-lost | 20 ++ modules/git/functions/git-dir | 16 ++ modules/git/functions/git-hub-browse | 58 ++++++ modules/git/functions/git-hub-shorten-url | 22 +++ modules/git/functions/git-ignore-add | 17 ++ modules/git/functions/git-root | 16 ++ .../git/functions/git-stash-clear-interactive | 22 +++ modules/git/functions/git-stash-dropped | 22 +++ modules/git/functions/git-stash-recover | 18 ++ modules/git/functions/git-submodule-move | 32 +++ modules/git/functions/git-submodule-remove | 27 +++ modules/git/init.zsh | 9 + modules/history-substring-search/external | 1 + modules/history-substring-search/init.zsh | 20 ++ modules/history/init.zsh | 46 +++++ modules/pacman/alias.zsh | 81 ++++++++ modules/pacman/helper_aur.zsh | 20 ++ modules/pacman/init.zsh | 37 ++++ modules/prompt/functions/prompt_eriner_setup | 153 +++++++++++++++ modules/prompt/init.zsh | 8 + modules/prompt/themes/eriner.zsh-theme | 153 +++++++++++++++ modules/spectrum/init.zsh | 65 +++++++ modules/ssh/init.zsh | 38 ++++ modules/syntax-highlighting/external | 1 + modules/syntax-highlighting/init.zsh | 8 + modules/utility/init.zsh | 30 +++ templates/zimrc | 50 +++++ templates/zlogin | 59 ++++++ templates/zshrc | 9 + 39 files changed, 1552 insertions(+) create mode 100644 .gitignore create mode 100644 .gitmodules create mode 100644 README.md create mode 100755 init.zsh create mode 160000 modules/completion/external create mode 100644 modules/completion/init.zsh create mode 100644 modules/directory/init.zsh create mode 100644 modules/environment/init.zsh create mode 100644 modules/git/alias.zsh create mode 100644 modules/git/functions/git-branch-current create mode 100644 modules/git/functions/git-commit-lost create mode 100644 modules/git/functions/git-dir create mode 100644 modules/git/functions/git-hub-browse create mode 100644 modules/git/functions/git-hub-shorten-url create mode 100644 modules/git/functions/git-ignore-add create mode 100644 modules/git/functions/git-root create mode 100644 modules/git/functions/git-stash-clear-interactive create mode 100644 modules/git/functions/git-stash-dropped create mode 100644 modules/git/functions/git-stash-recover create mode 100644 modules/git/functions/git-submodule-move create mode 100644 modules/git/functions/git-submodule-remove create mode 100644 modules/git/init.zsh create mode 160000 modules/history-substring-search/external create mode 100644 modules/history-substring-search/init.zsh create mode 100644 modules/history/init.zsh create mode 100644 modules/pacman/alias.zsh create mode 100644 modules/pacman/helper_aur.zsh create mode 100644 modules/pacman/init.zsh create mode 100644 modules/prompt/functions/prompt_eriner_setup create mode 100644 modules/prompt/init.zsh create mode 100644 modules/prompt/themes/eriner.zsh-theme create mode 100644 modules/spectrum/init.zsh create mode 100644 modules/ssh/init.zsh create mode 160000 modules/syntax-highlighting/external create mode 100644 modules/syntax-highlighting/init.zsh create mode 100644 modules/utility/init.zsh create mode 100644 templates/zimrc create mode 100644 templates/zlogin create mode 100644 templates/zshrc diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6d81a22 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.swp +*.zwc diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..73d1432 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,9 @@ +[submodule "modules/history-substring-search/external"] + path = modules/history-substring-search/external + url = git@github.com:zsh-users/zsh-history-substring-search.git +[submodule "modules/completion/external"] + path = modules/completion/external + url = git@github.com:zsh-users/zsh-completions.git +[submodule "modules/syntax-highlighting/external"] + path = modules/syntax-highlighting/external + url = git@github.com:zsh-users/zsh-syntax-highlighting.git diff --git a/README.md b/README.md new file mode 100644 index 0000000..20c5534 --- /dev/null +++ b/README.md @@ -0,0 +1,57 @@ +ZIM - Zsh IMproved +================== +Moving to Zsh because you heard it was cool? Tried other frameworks but found them slow? +Want something that works without spending hours configuring sane settings? Want to be the conqueror of shells? + +Meet Zim. + +What is Zim? +------------ +Zim is a Zsh configuration fromework that prides itself on speed and modularity. +Zim is very easy to customize and add your own functionality. But worry not! You don't *have* to if that's not your cup of tea! + +Zim comes with a rich set of default modules and features without comprimising on speed or functionality! + +What does Zim offer? +----------------- +If you're here, it means you want to see the cool shit Zim has to offer. + +#### Themes +> Images of cascading themes + +#### Fish-shell History Navigation +> GIF OF history-substring-search + +#### Syntax Highlighting +> GIF of syntax highlighting + +#### Speed +> possible side-by-side comparison of oh-my-zsh/zprezto/zim + +#### And much more! +Zim has many modules! Enable as many or as few as you'd like. + +Installation +------------ +Installing Zim is easy. If you have a different shell framework installed (like oh-my-zsh or prezto), +uninstall those first to prevent conflicts. + +1. In Zsh, clone the repository: + ``` + git clone --recursive https://github.com/Eriner/zim.git ${ZDOTDIR:-$HOME}/.zim + ``` + +2. Copy the template configuration files (or append to existing configs): + ``` + setopt EXTENDED_GLOB + for template_file ( ${ZDOTDIR:-$HOME}/.zim/templates/* ); do + cat ${template_file} | tee -a ${ZDOTDIR:-$HOME}/.$(basename ${template_file}) > /dev/null + done + ``` + +3. Set Zsh as the default shell: + ``` + chsh -s $(which zsh) + ``` + +4. Open a new terminal and admire your work! diff --git a/init.zsh b/init.zsh new file mode 100755 index 0000000..5552366 --- /dev/null +++ b/init.zsh @@ -0,0 +1,47 @@ +# +# Zim initializition +# + +# Define zim location +ZIM="${ZDOTDIR:-$HOME}/.zim" + +# Source user configuration +if [[ -s "${ZDOTDIR:-$HOME}/.zimrc" ]]; then + source "${ZDOTDIR:-$HOME}/.zimrc" +fi + +load_zim_module() { + local wanted_module + + for wanted_module ($zmodules); do + if [[ -s "${ZIM}/modules/$wanted_module/init.zsh" ]]; then + source "${ZIM}/modules/$wanted_module/init.zsh" + elif [[ ! -d "${ZIM}/modules/$wanted_module" ]]; then + print "No such module \"$wanted_module\"." >&2 + fi + done +} + +load_zim_function() { + local function_glob='^([_.]*|prompt_*_setup|README*)(-.N:t)' + local mod_function + + # autoload searches fpath for function locations; add enabled module function paths + fpath+=(${argv:+${ZIM}/modules/${^zmodules}/functions(/FN)}) + + function { + setopt LOCAL_OPTIONS EXTENDED_GLOB + + for mod_function in ${ZIM}/modules/${^zmodules}/functions/$~function_glob; do + autoload -Uz ${mod_function} + done + } +} + +# Load zim functions +load_zim_function ${zmodules[@]} + +# Load zim modules +load_zim_module ${zmodules[@]} + +unset zmodules diff --git a/modules/completion/external b/modules/completion/external new file mode 160000 index 0000000..c2dde89 --- /dev/null +++ b/modules/completion/external @@ -0,0 +1 @@ +Subproject commit c2dde89fb34e2734106e50689bf4127f6b0a288d diff --git a/modules/completion/init.zsh b/modules/completion/init.zsh new file mode 100644 index 0000000..be0acfe --- /dev/null +++ b/modules/completion/init.zsh @@ -0,0 +1,108 @@ +# +# Completion enhancements +# + + +# +# initialization +# + +# if it's a dumb terminal, return. +if [[ ${TERM} == 'dumb' ]]; then + return 1 +fi + +# add the completions to the fpath +fpath+=(${0:h}/external/src) + +# load and initialize the completion system +autoload -Uz compinit && compinit -C -d ${ZDOTDIR:-$HOME}/.zcompdump +{ + # zcomple the .zcompdump in the background + local zcompdump=${ZDOTDIR:-$HOME}/.zcompdump + + if [[ -s ${zcompdump} && ( ! -s ${zcompdump}.zwc || ${zcompdump} -nt ${zcompdump}.zwc) ]]; then + zcompile ${zcompdump} + fi + + unset zcompdump +} &! + + +# +# zsh options +# + +# If a completion is performed with the cursor within a word, and a full completion is inserted, +# the cursor is moved to the end of the word +setopt ALWAYS_TO_END + +# Automatically use menu completion after the second consecutive request for completion +setopt AUTO_MENU + +# Automatically list choices on an ambiguous completion. +setopt AUTO_LIST + +# Perform a path search even on command names with slashes in them. +setopt PATH_DIRS + +# Make globbing (filename generation) sensitive to case. +unsetopt CASE_GLOB + +# On an ambiguous completion, instead of listing possibilities or beeping, insert the first match immediately. +# Then when completion is requested again, remove the first match and insert the second match, etc. +unsetopt MENU_COMPLETE + + +# +# completion module options +# + +# group matches and describe. +zstyle ':completion:*:*:*:*:*' menu select +zstyle ':completion:*:matches' group 'yes' +zstyle ':completion:*:options' description 'yes' +zstyle ':completion:*:options' auto-description '%d' +zstyle ':completion:*:corrections' format ' %F{green}-- %d (errors: %e) --%f' +zstyle ':completion:*:descriptions' format ' %F{yellow}-- %d --%f' +zstyle ':completion:*:messages' format ' %F{purple} -- %d --%f' +zstyle ':completion:*:warnings' format ' %F{red}-- no matches found --%f' +zstyle ':completion:*:default' list-prompt '%S%M matches%s' +zstyle ':completion:*' format ' %F{yellow}-- %d --%f' +zstyle ':completion:*' group-name '' +zstyle ':completion:*' verbose yes +zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*' + +# directories +zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS} +zstyle ':completion:*:*:cd:*' tag-order local-directories directory-stack path-directories +zstyle ':completion:*:*:cd:*:directory-stack' menu yes select +zstyle ':completion:*:-tilde-:*' group-order 'named-directories' 'path-directories' 'expand' +zstyle ':completion:*' squeeze-slashes true + +# enable caching +zstyle ':completion::complete:*' use-cache on +zstyle ':completion::complete:*' cache-path "${ZDOTDIR:-$HOME}/.zcompcache" + +# ignore useless commands and functions +zstyle ':completion:*:functions' ignored-patterns '(_*|pre(cmd|exec)|prompt_*)' + +# completion sorting +zstyle ':completion:*:*:-subscript-:*' tag-order indexes parameters + +# Man +zstyle ':completion:*:manuals' separate-sections true +zstyle ':completion:*:manuals.(^1*)' insert-sections true + +# history +zstyle ':completion:*:history-words' stop yes +zstyle ':completion:*:history-words' remove-all-dups yes +zstyle ':completion:*:history-words' list false +zstyle ':completion:*:history-words' menu yes + +# ignore multiple entries. +zstyle ':completion:*:(rm|kill|diff):*' ignore-line other +zstyle ':completion:*:rm:*' file-patterns '*:all-files' + +# smart editor completion +zstyle ':completion:*:(nano|vim|nvim|vi|emacs|e):*' ignored-patterns '*.(wav|mp3|flac|ogg|mp4|avi|mkv|webm|iso|dmg|so|o|a|bin|exe|dll|pcap|7z|zip|tar|gz|bz2|rar|deb|pkg|gzip|pdf|mobi|epub|png|jpeg|jpg|gif)' diff --git a/modules/directory/init.zsh b/modules/directory/init.zsh new file mode 100644 index 0000000..02afe3d --- /dev/null +++ b/modules/directory/init.zsh @@ -0,0 +1,38 @@ +# +# Directory navigation options +# + +# +# Navigation +# + +# If a command is issued that can’t be executed as a normal command, +# and the command is the name of a directory, perform the cd command to that directory. +setopt AUTO_CD + +# Make cd push the old directory onto the directory stack. +setopt AUTO_PUSHD + +# Don’t push multiple copies of the same directory onto the directory stack. +setopt PUSHD_IGNORE_DUPS + +# Do not print the directory stack after pushd or popd. +setopt PUSHD_SILENT + +# Have pushd with no arguments act like ‘pushd $HOME’. +setopt PUSHD_TO_HOME + +# +# Globbing and fds +# + +# Treat the ‘#’, ‘~’ and ‘^’ characters as part of patterns for filename generation, etc. +# (An initial unquoted ‘~’ always produces named directory expansion.) +setopt EXTENDED_GLOB + +# Perform implicit tees or cats when multiple redirections are attempted. +setopt MULTIOS + +# Allows ‘>’ redirection to truncate existing files. Otherwise ‘>!’ or ‘>|’ must be used to truncate a file. +# If the option is not set, and the option APPEND_CREATE is also not set, ‘>>!’ or ‘>>|’ must be used to create a file. +unsetopt CLOBBER diff --git a/modules/environment/init.zsh b/modules/environment/init.zsh new file mode 100644 index 0000000..8677757 --- /dev/null +++ b/modules/environment/init.zsh @@ -0,0 +1,28 @@ +# +# generic options and environment settings +# + +# use smart URL pasting and escaping +autoload -Uz url-quote-magic bracketed-paste-magic +zle -N self-insert url-quote-magic +zle -N bracketed-paste bracketed-paste-magic + +# Treat single word simple commands without redirection as candidates for resumption of an existing job. +setopt AUTO_RESUME + +# List jobs in the long format by default. +setopt LONG_LIST_JOBS + +# Report the status of background jobs immediately, rather than waiting until just before printing a prompt. +setopt NOTIFY + +# Run all background jobs at a lower priority. This option is set by default. +unsetopt BG_NICE + +# Send the HUP signal to running jobs when the shell exits. +unsetopt HUP + +# Report the status of background and suspended jobs before exiting a shell with job control; +# a second attempt to exit the shell will succeed. +# NO_CHECK_JOBS is best used only in combination with NO_HUP, else such jobs will be killed automatically +unsetopt CHECK_JOBS diff --git a/modules/git/alias.zsh b/modules/git/alias.zsh new file mode 100644 index 0000000..20b7781 --- /dev/null +++ b/modules/git/alias.zsh @@ -0,0 +1,184 @@ +# +# Git aliases. +# + +# +# Settings +# + +# Log +_git_log_medium_format='%C(bold)Commit:%C(reset) %C(green)%H%C(red)%d%n%C(bold)Author:%C(reset) %C(cyan)%an <%ae>%n%C(bold)Date:%C(reset) %C(blue)%ai (%ar)%C(reset)%n%+B' +_git_log_oneline_format='%C(green)%h%C(reset) %s%C(red)%d%C(reset)%n' +_git_log_brief_format='%C(green)%h%C(reset) %s%n%C(blue)(%ar by %an)%C(red)%d%C(reset)%n' + +# +# Aliases +# + +# Git +alias g='git' + +# Branch (b) +alias gb='git branch' +alias gbc='git checkout -b' +alias gbl='git branch -v' +alias gbL='git branch -av' +alias gbx='git branch -d' +alias gbX='git branch -D' +alias gbm='git branch -m' +alias gbM='git branch -M' +alias gbs='git show-branch' +alias gbS='git show-branch -a' + +# Commit (c) +alias gc='git commit --verbose' +alias gca='git commit --verbose --all' +alias gcm='git commit --message' +alias gco='git checkout' +alias gcO='git checkout --patch' +alias gcf='git commit --amend --reuse-message HEAD' +alias gcF='git commit --verbose --amend' +alias gcp='git cherry-pick --ff' +alias gcP='git cherry-pick --no-commit' +alias gcr='git revert' +alias gcR='git reset "HEAD^"' +alias gcs='git show' +alias gcl='git-commit-lost' +alias gcS='git commit -S' +alias gpS='git show --pretty=short --show-signature' + +# Conflict (C) +alias gCl='git status | sed -n "s/^.*both [a-z]*ed: *//p"' +alias gCa='git add $(gCl)' +alias gCe='git mergetool $(gCl)' +alias gCo='git checkout --ours --' +alias gCO='gCo $(gCl)' +alias gCt='git checkout --theirs --' +alias gCT='gCt $(gCl)' + +# Data (d) +alias gd='git ls-files' +alias gdc='git ls-files --cached' +alias gdx='git ls-files --deleted' +alias gdm='git ls-files --modified' +alias gdu='git ls-files --other --exclude-standard' +alias gdk='git ls-files --killed' +alias gdi='git status --porcelain --short --ignored | sed -n "s/^!! //p"' + +# Fetch (f) +alias gf='git fetch' +alias gfc='git clone' +alias gfm='git pull' +alias gfr='git pull --rebase' +alias gfu='git remote update -p; git merge --ff-only @\{u\}' + +# Grep (g) +alias gg='git grep' +alias ggi='git grep --ignore-case' +alias ggl='git grep --files-with-matches' +alias ggL='git grep --files-without-matches' +alias ggv='git grep --invert-match' +alias ggw='git grep --word-regexp' + +# Index (i) +alias gia='git add' +alias giA='git add --patch' +alias giu='git add --update' +alias gid='git diff --no-ext-diff --cached' +alias giD='git diff --no-ext-diff --cached --word-diff' +alias gir='git reset' +alias giR='git reset --patch' +alias gix='git rm -r --cached' +alias giX='git rm -rf --cached' + +# Log (l) +alias gl='git log --topo-order --pretty=format:"${_git_log_medium_format}"' +alias gls='git log --topo-order --stat --pretty=format:"${_git_log_medium_format}"' +alias gld='git log --topo-order --stat --patch --full-diff --pretty=format:"${_git_log_medium_format}"' +alias glo='git log --topo-order --pretty=format:"${_git_log_oneline_format}"' +alias glg='git log --topo-order --all --graph --pretty=format:"${_git_log_oneline_format}"' +alias glb='git log --topo-order --pretty=format:"${_git_log_brief_format}"' +alias glc='git shortlog --summary --numbered' +alias glS='git log --show-signature' + +# Merge (m) +alias gm='git merge' +alias gmC='git merge --no-commit' +alias gmF='git merge --no-ff' +alias gma='git merge --abort' +alias gmt='git mergetool' + +# Push (p) +alias gp='git push' +alias gpf='git push --force' +alias gpa='git push --all' +alias gpA='git push --all && git push --tags' +alias gpt='git push --tags' +alias gpc='git push --set-upstream origin "$(git-branch-current 2> /dev/null)"' +alias gpp='git pull origin "$(git-branch-current 2> /dev/null)" && git push origin "$(git-branch-current 2> /dev/null)"' + +# Rebase (r) +alias gr='git rebase' +alias gra='git rebase --abort' +alias grr='git rebase --continue' +alias gri='git rebase --interactive' +alias grs='git rebase --skip' + +# Remote (R) +alias gR='git remote' +alias gRl='git remote --verbose' +alias gRa='git remote add' +alias gRx='git remote rm' +alias gRm='git remote rename' +alias gRu='git remote update' +alias gRp='git remote prune' +alias gRs='git remote show' +alias gRb='git-hub-browse' + +# Stash (s) +alias gs='git stash' +alias gsa='git stash apply' +alias gsx='git stash drop' +alias gsX='git-stash-clear-interactive' +alias gsl='git stash list' +alias gsL='git-stash-dropped' +alias gsd='git stash show --patch --stat' +alias gsp='git stash pop' +alias gsr='git-stash-recover' +alias gss='git stash save --include-untracked' +alias gsS='git stash save --patch --no-keep-index' +alias gsw='git stash save --include-untracked --keep-index' + +# Submodule (S) +alias gS='git submodule' +alias gSa='git submodule add' +alias gSf='git submodule foreach' +alias gSi='git submodule init' +alias gSI='git submodule update --init --recursive' +alias gSl='git submodule status' +alias gSm='git-submodule-move' +alias gSs='git submodule sync' +alias gSu='git submodule foreach git pull origin master' +alias gSx='git-submodule-remove' + +# Tag (t) +alias gts='git tag -s' +alias gtv='git verify-tag' + +# Working Copy (w) +alias gws='git status --short' +alias gwS='git status' +alias gwd='git diff --no-ext-diff' +alias gwD='git diff --no-ext-diff --word-diff' +alias gwr='git reset --soft' +alias gwR='git reset --hard' +alias gwc='git clean -n' +alias gwC='git clean -df' +alias gwx='git rm -r' +alias gwX='git rm -rf' + +# Misc +alias g..='cd $(git-root || echo ".")' + +# Cleanup +unset _git_log{,} diff --git a/modules/git/functions/git-branch-current b/modules/git/functions/git-branch-current new file mode 100644 index 0000000..944ffe2 --- /dev/null +++ b/modules/git/functions/git-branch-current @@ -0,0 +1,20 @@ +# +# Displays the current Git branch. +# +# Authors: +# Sorin Ionescu +# + +if ! git rev-parse 2> /dev/null; then + print "$0: not a repository: $PWD" >&2 + return 1 +fi + +local ref="$(git symbolic-ref HEAD 2> /dev/null)" + +if [[ -n "$ref" ]]; then + print "${ref#refs/heads/}" + return 0 +else + return 1 +fi diff --git a/modules/git/functions/git-commit-lost b/modules/git/functions/git-commit-lost new file mode 100644 index 0000000..75ab571 --- /dev/null +++ b/modules/git/functions/git-commit-lost @@ -0,0 +1,20 @@ +# +# Lists lost Git commits. +# +# Authors: +# Sorin Ionescu +# + +if ! is-true "$(git rev-parse --is-inside-work-tree 2> /dev/null)"; then + print "$0: not a repository work tree: $PWD" >&2 + return 1 +fi + +git fsck 2> /dev/null \ + | grep "^dangling commit" \ + | awk '{print $3}' \ + | git log \ + --date-order \ + --no-walk \ + --stdin \ + --pretty=format:${_git_log_oneline_format} diff --git a/modules/git/functions/git-dir b/modules/git/functions/git-dir new file mode 100644 index 0000000..7e16ca8 --- /dev/null +++ b/modules/git/functions/git-dir @@ -0,0 +1,16 @@ +# +# Displays the path to the Git directory. +# +# Authors: +# Sorin Ionescu +# + +local git_dir="${$(git rev-parse --git-dir):A}" + +if [[ -n "$git_dir" ]]; then + print "$git_dir" + return 0 +else + print "$0: not a repository: $PWD" >&2 + return 1 +fi diff --git a/modules/git/functions/git-hub-browse b/modules/git/functions/git-hub-browse new file mode 100644 index 0000000..549a544 --- /dev/null +++ b/modules/git/functions/git-hub-browse @@ -0,0 +1,58 @@ +# +# Opens a GitHub repository in the default browser. +# +# Authors: +# Sorin Ionescu +# + +if ! is-true "$(git rev-parse --is-inside-work-tree 2> /dev/null)"; then + print "$0: not a repository work tree: $PWD" >&2 + return 1 +fi + +local remotes remote references reference file url + +remote="${1:-origin}" +remotes=($(git config --get-regexp 'remote.*.url' | cut -d. -f2)) + +if (( $remotes[(i)$remote] == $#remotes + 1 )); then + print "$0: remote not found: $remote" >&2 + return 1 +fi + +url=$( + git config --get "remote.${remote}.url" \ + | sed -En "s/(git|https?)(@|:\/\/)github.com(:|\/)(.+)\/(.+).git/https:\/\/github.com\/\4\/\5/p" +) + +reference="${${2:-$(git-branch-current)}:-HEAD}" +references=( + HEAD + ${$(git ls-remote --heads --tags "$remote" | awk '{print $2}')##refs/(heads|tags)/} +) + +if (( $references[(i)$reference] == $#references + 1 )); then + print "$0: branch or tag not found: $reference" >&2 + return 1 +fi + +if [[ "$reference" == 'HEAD' ]]; then + reference="$(git rev-parse HEAD 2>/dev/null)" +fi + +file="$3" + +if [[ -n "$url" ]]; then + url="${url}/tree/${reference}/${file}" + + if (( $+commands[$BROWSER] )); then + "$BROWSER" "$url" + return 0 + else + print "$0: browser not set or set to a non-existent browser" >&2 + return 1 + fi +else + print "$0: not a Git repository or remote not set" >&2 + return 1 +fi diff --git a/modules/git/functions/git-hub-shorten-url b/modules/git/functions/git-hub-shorten-url new file mode 100644 index 0000000..d37b04e --- /dev/null +++ b/modules/git/functions/git-hub-shorten-url @@ -0,0 +1,22 @@ +# +# Shortens GitHub URLs. +# +# Authors: +# Sorin Ionescu +# + +local url="$1" + +if [[ "$url" == '-' ]]; then + read url <&0 +fi + +if [[ -z "$url" ]]; then + print "usage: $0 [ url | - ]" >&2 +fi + +if (( $+commands[curl] )); then + curl -s -i 'http://git.io' -F "url=$url" | sed -n 's/^Location: //p' +else + print "$0: command not found: curl" >&2 +fi diff --git a/modules/git/functions/git-ignore-add b/modules/git/functions/git-ignore-add new file mode 100644 index 0000000..0e93f0d --- /dev/null +++ b/modules/git/functions/git-ignore-add @@ -0,0 +1,17 @@ +# +# Adds files passed as parameters to .gitignore in project root +# +# Authors: +# Matt Hamilton +# + +# make sure we have a git-root +if ! git-root &> /dev/null; then + print 'not in a git repository' >&2 + return 1 +fi + +# we are in a git repository. add parameters to .gitignore +for file in "$@"; do + print "$file" >>! $(git-root)/.gitignore +done diff --git a/modules/git/functions/git-root b/modules/git/functions/git-root new file mode 100644 index 0000000..712e4fe --- /dev/null +++ b/modules/git/functions/git-root @@ -0,0 +1,16 @@ +# +# Displays the path to the working tree root. +# +# Authors: +# Sorin Ionescu +# + +local root="$(git rev-parse --show-toplevel 2> /dev/null)" + +if [[ -n "$root" ]]; then + print "$root" + return 0 +else + print "$0: not a repository work tree: $PWD" >&2 + return 1 +fi diff --git a/modules/git/functions/git-stash-clear-interactive b/modules/git/functions/git-stash-clear-interactive new file mode 100644 index 0000000..e45165c --- /dev/null +++ b/modules/git/functions/git-stash-clear-interactive @@ -0,0 +1,22 @@ +# +# Asks for confirmation before clearing the Git stash. +# +# Authors: +# Sorin Ionescu +# + +if ! is-true "$(git rev-parse --is-inside-work-tree 2> /dev/null)"; then + print "$0: not a repository work tree: $PWD" >&2 + return 1 +fi + +local stashed + +if [[ -f "$(git-dir)/refs/stash" ]]; then + stashed="$(git stash list 2> /dev/null | wc -l | awk '{print $1}')" + if (( $stashed > 0 )); then + if read -q "?Clear $stashed stashed state(s) [y/N]? "; then + git stash clear + fi + fi +fi diff --git a/modules/git/functions/git-stash-dropped b/modules/git/functions/git-stash-dropped new file mode 100644 index 0000000..5158070 --- /dev/null +++ b/modules/git/functions/git-stash-dropped @@ -0,0 +1,22 @@ +# +# Lists dropped Git stashed states. +# +# Authors: +# Sorin Ionescu +# + +if ! is-true "$(git rev-parse --is-inside-work-tree 2> /dev/null)"; then + print "$0: not a repository work tree: $PWD" >&2 + return 1 +fi + +git fsck --unreachable 2> /dev/null \ + | grep 'commit' \ + | awk '{print $3}' \ + | git log \ + --pretty=format:${_git_log_oneline_format} \ + --extended-regexp \ + --grep="${1:-(WIP )?[Oo]n [^:]+:}" \ + --merges \ + --no-walk \ + --stdin diff --git a/modules/git/functions/git-stash-recover b/modules/git/functions/git-stash-recover new file mode 100644 index 0000000..6add26f --- /dev/null +++ b/modules/git/functions/git-stash-recover @@ -0,0 +1,18 @@ +# +# Recovers dropped Git stashed states. +# +# Authors: +# Sorin Ionescu +# + +if ! is-true "$(git rev-parse --is-inside-work-tree 2> /dev/null)"; then + print "$0: not a repository work tree: $PWD" >&2 + return 1 +fi + +local commit + +for commit in "$@"; do + git update-ref \ + -m "$(git log -1 --pretty="format:%s" "$commit")" refs/stash "$commit" +done diff --git a/modules/git/functions/git-submodule-move b/modules/git/functions/git-submodule-move new file mode 100644 index 0000000..34c5e44 --- /dev/null +++ b/modules/git/functions/git-submodule-move @@ -0,0 +1,32 @@ +# +# Moves a Git submodule. +# +# Authors: +# Sorin Ionescu +# + +if ! is-true "$(git rev-parse --is-inside-work-tree 2> /dev/null)"; then + print "$0: not a repository work tree: $PWD" >&2 + return 1 +elif [[ "$PWD" != "$(git-root)" ]]; then + print "$0: must be run from the root of the work tree" >&2 + return 1 +fi + +local src="$1" +local dst="$2" +local url + +url="$(git config --file "$(git-root)/.gitmodules" --get "submodule.${src}.url")" + +if [[ -z "$url" ]]; then + print "$0: submodule not found: $src" >&2 + return 1 +fi + +mkdir -p "${dst:h}" + +git-submodule-remove "$src" +git submodule add "$url" "$dst" + +return 0 diff --git a/modules/git/functions/git-submodule-remove b/modules/git/functions/git-submodule-remove new file mode 100644 index 0000000..852b9cd --- /dev/null +++ b/modules/git/functions/git-submodule-remove @@ -0,0 +1,27 @@ +# +# Removes a Git submodule. +# +# Authors: +# Sorin Ionescu +# + +if ! is-true "$(git rev-parse --is-inside-work-tree 2> /dev/null)"; then + print "$0: not a repository work tree: $PWD" >&2 + return 1 +elif [[ "$PWD" != "$(git-root)" ]]; then + print "$0: must be run from the root of the work tree" >&2 + return 1 +elif ! git config --file .gitmodules --get "submodule.${1}.path" &>/dev/null; then + print "$0: submodule not found: $1" >&2 + return 1 +fi + +git config --file "$(git-dir)/config" --remove-section "submodule.${1}" &>/dev/null +git config --file "$(git-root)/.gitmodules" --remove-section "submodule.${1}" &>/dev/null +git add .gitmodules + +git rm --cached -rf "${1}" +rm -rf "${1}" +rm -rf "$(git-dir)/modules/${1}" + +return 0 diff --git a/modules/git/init.zsh b/modules/git/init.zsh new file mode 100644 index 0000000..e6eb0d4 --- /dev/null +++ b/modules/git/init.zsh @@ -0,0 +1,9 @@ +# +# git aliases and functions +# + +if (( ! $+commands[git] )); then + return 1 +fi + +source "${0:h}/alias.zsh" diff --git a/modules/history-substring-search/external b/modules/history-substring-search/external new file mode 160000 index 0000000..2f8a5f8 --- /dev/null +++ b/modules/history-substring-search/external @@ -0,0 +1 @@ +Subproject commit 2f8a5f8fe33d2f6165ac23336ed074296d65dec9 diff --git a/modules/history-substring-search/init.zsh b/modules/history-substring-search/init.zsh new file mode 100644 index 0000000..7f5f404 --- /dev/null +++ b/modules/history-substring-search/init.zsh @@ -0,0 +1,20 @@ +# +# enables searching history with substrings +# + +# source script +source ${0:h}/external/zsh-history-substring-search.zsh || return 1 + +# set options +HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_FOUND='bg=magenta,fg=white,bold' +HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_NOT_FOUND='bg=red,fg=white,bold' +HISTORY_SUBSTRING_SEARCH_GLOBBING_FLAGS='i' + +# bind UP and DOWN keys +zmodload zsh/terminfo +bindkey "$terminfo[kcuu1]" history-substring-search-up +bindkey "$terminfo[kcud1]" history-substring-search-down + +# bind UP and DOWN arrow keys (compatibility fallback) +bindkey '^[[A' history-substring-search-up +bindkey '^[[B' history-substring-search-down diff --git a/modules/history/init.zsh b/modules/history/init.zsh new file mode 100644 index 0000000..3893df9 --- /dev/null +++ b/modules/history/init.zsh @@ -0,0 +1,46 @@ +# +# Configures history options +# + +# sets the location of the history file +HISTFILE="${ZDOTDIR:-$HOME}/.zhistory" + +# limit of history entries +HISTSIZE=10000 +SAVEHIST=10000 + +# Perform textual history expansion, csh-style, treating the character ‘!’ specially. +setopt BANG_HIST + +# Save each command’s beginning timestamp (in seconds since the epoch) and the duration (in seconds) to the history file. +# ‘: :;’. +setopt EXTENDED_HISTORY + +# This options works like APPEND_HISTORY except that new history lines are added to the $HISTFILE incrementally +# (as soon as they are entered), rather than waiting until the shell exits. +setopt INC_APPEND_HISTORY + +# Shares history across all sessions rather than waiting for a new shell invocation to read the history file. +setopt SHARE_HISTORY + +# Do not enter command lines into the history list if they are duplicates of the previous event. +setopt HIST_IGNORE_DUPS + +# If a new command line being added to the history list duplicates an older one, +# the older command is removed from the list (even if it is not the previous event). +setopt HIST_IGNORE_ALL_DUPS + +# Remove command lines from the history list when the first character on the line is a space, +# or when one of the expanded aliases contains a leading space. +setopt HIST_IGNORE_SPACE + +# When writing out the history file, older commands that duplicate newer ones are omitted. +setopt HIST_SAVE_NO_DUPS + +# Whenever the user enters a line with history expansion, don’t execute the line directly; +# instead, perform history expansion and reload the line into the editing buffer. +setopt HIST_VERIFY + + +# Lists the ten most used commands. +alias history-stat="history 0 | awk '{print \$2}' | sort | uniq -c | sort -n -r | head" diff --git a/modules/pacman/alias.zsh b/modules/pacman/alias.zsh new file mode 100644 index 0000000..827f900 --- /dev/null +++ b/modules/pacman/alias.zsh @@ -0,0 +1,81 @@ +# +# Pacman aliases +# + +# ${zpacman_frontend} is provided by either .zimrc or (if not set) init.zsh +# The zpacman_frontend is _only_ used for package installs. + +# +# General +# + +alias pacman=${zpacman_frontend} +alias pac=${zpacman_frontend} + +# +# Build +# + +# build package in current directory, cleanup, and install +alias pacb='makepkg -sci' + +# +# Install +# + +#NOTE: Installing/upgrading individual packages is NOT supported. Sync and upgrade ALL on install. + +# install, sync, and upgrade packages +alias paci='sudo ${zpacman_frontend} -Syu' + +# install, sync, and upgrade packages (forcibly refresh package lists) +alias pacu='sudo ${zpacman_frontend} -Syyu' + +# install packages by filename +alias pacU='sudo ${zpacman_frontend} -U' + +# install all packages in current directory +alias pacd='sudo ${zpacman_frontend} -U *.pkg.tar.xz' + + +# +# Remove +# + +# remove package and unneeded dependencies +alias pacr='sudo pacman -R' + +# remove package, unneeded dependencies, and configuration files +alias pacrm='sudo pacman -Rns' + + +# +# Query +# + +# query package information from the remote repository +alias pacq='pacman -Si' + +# query package information from the local repository +alias pacQ='pacman -Qi' + + +# +# Search +# + +# search for package in the remote repository +alias pacs='pacman -Ss' + +# search for the package in the local repository +alias pacS='pacman -Qs' + +# +# Orphans +# + +# list orphan packages +alias pacol='pacman -Qdt' + +# remove orphan packages +alias pacrl='sudo pacman -Rns $(pacman -Qtdq)' diff --git a/modules/pacman/helper_aur.zsh b/modules/pacman/helper_aur.zsh new file mode 100644 index 0000000..1a3c193 --- /dev/null +++ b/modules/pacman/helper_aur.zsh @@ -0,0 +1,20 @@ +# +# AUR aliases +# + +# download and build AUR package +aurb() { + git clone https://aur.archlinux.org/$1.git && cd $1 && makepkg -sci +} + +# only download aur package; do not build +aurd() { + git clone https://aur.archlinux.org/$1.git +} + +# remove old package, rebuild, and install. +#NOTE: this is will remove any unstashed/uncommitted changes. +# due to how makepkg will update the PKGBUILD, a git pull alone will not suffice. +auru() { + git reset HEAD --hard && git pull && rm -f *.pkg.tar.xz || true && makepkg -sci +} diff --git a/modules/pacman/init.zsh b/modules/pacman/init.zsh new file mode 100644 index 0000000..f1397f0 --- /dev/null +++ b/modules/pacman/init.zsh @@ -0,0 +1,37 @@ +# +# Pacman aliases and functions +# + +# ensure pacman is available +if (( ! $+commands[pacman] )); then + return 1 +fi + +# find if there is a pacman wrapper available (and not set in .zimrc) +if [[ ${zpacman_frontend} == 'auto' ]]; then + # no frontend set in config; test for common frontends. + + if (( $+commands[powerpill] )); then + zpacman_frontend='powerpill' + elif (( $+commands[pacmatic] )); then + zpacman_frontend='pacmatic' + else + zpacman_frontend='pacman' + fi +elif (( ! $+commands[${zpacman_frontend}] )); then + print "pacman frontend \"${zpacman_frontend}\" is invalid or not installed. Reverting to \"pacman\"." >&2 + print "you can fix this error by editing the 'zpacman_frontend' variable in your .zimrc" >&2 + zpacman_frontend='pacman' +fi + +# source helper functions/aliases +for helper ( ${zpacman_helper[@]} ); do + if [[ -s ${0:h}/helper_${helper}.zsh ]]; then + source ${0:h}/helper_${helper}.zsh + else + print "no such helper script \"helper_${helper}.zsh\"" >&2 + fi +done + +# source pacman aliases +source ${0:h}/alias.zsh diff --git a/modules/prompt/functions/prompt_eriner_setup b/modules/prompt/functions/prompt_eriner_setup new file mode 100644 index 0000000..6f76a64 --- /dev/null +++ b/modules/prompt/functions/prompt_eriner_setup @@ -0,0 +1,153 @@ +# vim:ft=zsh ts=2 sw=2 sts=2 +# +# agnoster's Theme - https://gist.github.com/3712874 +# A Powerline-inspired theme for ZSH +# +# # README +# +# In order for this theme to render correctly, you will need a +# [Powerline-patched font](https://gist.github.com/1595572). +# +# In addition, I recommend the +# [Solarized theme](https://github.com/altercation/solarized/) and, if you're +# using it on Mac OS X, [iTerm 2](http://www.iterm2.com/) over Terminal.app - +# it has significantly better color fidelity. +# +# # Goals +# +# The aim of this theme is to only show you *relevant* information. Like most +# prompts, it will only show git information when in a git working directory. +# However, it goes a step further: everything from the current user and +# hostname to whether the last call exited with an error to whether background +# jobs are running in this shell will all be displayed automatically when +# appropriate. + +### Segment drawing +# A few utility functions to make it easy and re-usable to draw segmented prompts + +CURRENT_BG='NONE' +PRIMARY_FG=black + +# Characters +SEGMENT_SEPARATOR="\ue0b0" +PLUSMINUS="\u00b1" +BRANCH="\ue0a0" +DETACHED="\u27a6" +CROSS="\u2718" +LIGHTNING="\u26a1" +GEAR="\u2699" + +# Begin a segment +# Takes two arguments, background and foreground. Both can be omitted, +# rendering default background/foreground. +prompt_segment() { + local bg fg + [[ -n $1 ]] && bg="%K{$1}" || bg="%k" + [[ -n $2 ]] && fg="%F{$2}" || fg="%f" + if [[ $CURRENT_BG != 'NONE' && $1 != $CURRENT_BG ]]; then + print -n "%{$bg%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR%{$fg%}" + else + print -n "%{$bg%}%{$fg%}" + fi + CURRENT_BG=$1 + [[ -n $3 ]] && print -n $3 +} + +# End the prompt, closing any open segments +prompt_end() { + if [[ -n $CURRENT_BG ]]; then + print -n "%{%k%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR" + else + print -n "%{%k%}" + fi + print -n "%{%f%}" + CURRENT_BG='' +} + +### Prompt components +# Each component will draw itself, and hide itself if no information needs to be shown + +# Context: user@hostname (who am I and where am I) +prompt_context() { + local user=`whoami` + + if [[ "$user" != "$DEFAULT_USER" || -n "$SSH_CONNECTION" ]]; then + prompt_segment $PRIMARY_FG default " %(!.%{%F{yellow}%}.)$user@%m " + fi +} + +# Git: branch/detached head, dirty status +prompt_git() { + local color ref + is_dirty() { + test -n "$(git status --porcelain --ignore-submodules)" + } + ref="$vcs_info_msg_0_" + if [[ -n "$ref" ]]; then + if is_dirty; then + color=yellow + ref="${ref} $PLUSMINUS" + else + color=green + ref="${ref} " + fi + if [[ "${ref/.../}" == "$ref" ]]; then + ref="$BRANCH $ref" + else + ref="$DETACHED ${ref/.../}" + fi + prompt_segment $color $PRIMARY_FG + print -Pn " $ref" + fi +} + +# Dir: current working directory +prompt_dir() { + prompt_segment cyan $PRIMARY_FG ' %~ ' +} + +# Status: +# - was there an error +# - am I root +# - are there background jobs? +prompt_status() { + local symbols + symbols=() + [[ $RETVAL -ne 0 ]] && symbols+="%{%F{red}%}$CROSS" + [[ $UID -eq 0 ]] && symbols+="%{%F{yellow}%}$LIGHTNING" + [[ $(jobs -l | wc -l) -gt 0 ]] && symbols+="%{%F{cyan}%}$GEAR" + + [[ -n "$symbols" ]] && prompt_segment $PRIMARY_FG default " $symbols " +} + +## Main prompt +prompt_agnoster_main() { + RETVAL=$? + CURRENT_BG='NONE' + prompt_status + prompt_context + prompt_dir + prompt_git + prompt_end +} + +prompt_agnoster_precmd() { + vcs_info + PROMPT='%{%f%b%k%}$(prompt_agnoster_main) ' +} + +prompt_agnoster_setup() { + autoload -Uz add-zsh-hook + autoload -Uz vcs_info + + prompt_opts=(cr subst percent) + + add-zsh-hook precmd prompt_agnoster_precmd + + zstyle ':vcs_info:*' enable git + zstyle ':vcs_info:*' check-for-changes false + zstyle ':vcs_info:git*' formats '%b' + zstyle ':vcs_info:git*' actionformats '%b (%a)' +} + +prompt_agnoster_setup "$@" diff --git a/modules/prompt/init.zsh b/modules/prompt/init.zsh new file mode 100644 index 0000000..2ee8f3a --- /dev/null +++ b/modules/prompt/init.zsh @@ -0,0 +1,8 @@ +# +# load user-defined prompt +# + +if [[ ! ${TERM} == (linux|*bsd*|dumb) ]] && [[ ${zprompt_theme} ]]; then + autoload -Uz promptinit && promptinit + prompt ${zprompt_theme} +fi diff --git a/modules/prompt/themes/eriner.zsh-theme b/modules/prompt/themes/eriner.zsh-theme new file mode 100644 index 0000000..6f76a64 --- /dev/null +++ b/modules/prompt/themes/eriner.zsh-theme @@ -0,0 +1,153 @@ +# vim:ft=zsh ts=2 sw=2 sts=2 +# +# agnoster's Theme - https://gist.github.com/3712874 +# A Powerline-inspired theme for ZSH +# +# # README +# +# In order for this theme to render correctly, you will need a +# [Powerline-patched font](https://gist.github.com/1595572). +# +# In addition, I recommend the +# [Solarized theme](https://github.com/altercation/solarized/) and, if you're +# using it on Mac OS X, [iTerm 2](http://www.iterm2.com/) over Terminal.app - +# it has significantly better color fidelity. +# +# # Goals +# +# The aim of this theme is to only show you *relevant* information. Like most +# prompts, it will only show git information when in a git working directory. +# However, it goes a step further: everything from the current user and +# hostname to whether the last call exited with an error to whether background +# jobs are running in this shell will all be displayed automatically when +# appropriate. + +### Segment drawing +# A few utility functions to make it easy and re-usable to draw segmented prompts + +CURRENT_BG='NONE' +PRIMARY_FG=black + +# Characters +SEGMENT_SEPARATOR="\ue0b0" +PLUSMINUS="\u00b1" +BRANCH="\ue0a0" +DETACHED="\u27a6" +CROSS="\u2718" +LIGHTNING="\u26a1" +GEAR="\u2699" + +# Begin a segment +# Takes two arguments, background and foreground. Both can be omitted, +# rendering default background/foreground. +prompt_segment() { + local bg fg + [[ -n $1 ]] && bg="%K{$1}" || bg="%k" + [[ -n $2 ]] && fg="%F{$2}" || fg="%f" + if [[ $CURRENT_BG != 'NONE' && $1 != $CURRENT_BG ]]; then + print -n "%{$bg%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR%{$fg%}" + else + print -n "%{$bg%}%{$fg%}" + fi + CURRENT_BG=$1 + [[ -n $3 ]] && print -n $3 +} + +# End the prompt, closing any open segments +prompt_end() { + if [[ -n $CURRENT_BG ]]; then + print -n "%{%k%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR" + else + print -n "%{%k%}" + fi + print -n "%{%f%}" + CURRENT_BG='' +} + +### Prompt components +# Each component will draw itself, and hide itself if no information needs to be shown + +# Context: user@hostname (who am I and where am I) +prompt_context() { + local user=`whoami` + + if [[ "$user" != "$DEFAULT_USER" || -n "$SSH_CONNECTION" ]]; then + prompt_segment $PRIMARY_FG default " %(!.%{%F{yellow}%}.)$user@%m " + fi +} + +# Git: branch/detached head, dirty status +prompt_git() { + local color ref + is_dirty() { + test -n "$(git status --porcelain --ignore-submodules)" + } + ref="$vcs_info_msg_0_" + if [[ -n "$ref" ]]; then + if is_dirty; then + color=yellow + ref="${ref} $PLUSMINUS" + else + color=green + ref="${ref} " + fi + if [[ "${ref/.../}" == "$ref" ]]; then + ref="$BRANCH $ref" + else + ref="$DETACHED ${ref/.../}" + fi + prompt_segment $color $PRIMARY_FG + print -Pn " $ref" + fi +} + +# Dir: current working directory +prompt_dir() { + prompt_segment cyan $PRIMARY_FG ' %~ ' +} + +# Status: +# - was there an error +# - am I root +# - are there background jobs? +prompt_status() { + local symbols + symbols=() + [[ $RETVAL -ne 0 ]] && symbols+="%{%F{red}%}$CROSS" + [[ $UID -eq 0 ]] && symbols+="%{%F{yellow}%}$LIGHTNING" + [[ $(jobs -l | wc -l) -gt 0 ]] && symbols+="%{%F{cyan}%}$GEAR" + + [[ -n "$symbols" ]] && prompt_segment $PRIMARY_FG default " $symbols " +} + +## Main prompt +prompt_agnoster_main() { + RETVAL=$? + CURRENT_BG='NONE' + prompt_status + prompt_context + prompt_dir + prompt_git + prompt_end +} + +prompt_agnoster_precmd() { + vcs_info + PROMPT='%{%f%b%k%}$(prompt_agnoster_main) ' +} + +prompt_agnoster_setup() { + autoload -Uz add-zsh-hook + autoload -Uz vcs_info + + prompt_opts=(cr subst percent) + + add-zsh-hook precmd prompt_agnoster_precmd + + zstyle ':vcs_info:*' enable git + zstyle ':vcs_info:*' check-for-changes false + zstyle ':vcs_info:git*' formats '%b' + zstyle ':vcs_info:git*' actionformats '%b (%a)' +} + +prompt_agnoster_setup "$@" diff --git a/modules/spectrum/init.zsh b/modules/spectrum/init.zsh new file mode 100644 index 0000000..45b9e23 --- /dev/null +++ b/modules/spectrum/init.zsh @@ -0,0 +1,65 @@ +# +# Provides for easier use of 256 colors and effects. +# + +# Return if requirements are not found. +if [[ "$TERM" == 'dumb' ]]; then + return 1 +fi + +typeset -gA FX FG BG + +FX=( + none "\e[00m" + normal "\e[22m" + bold "\e[01m" no-bold "\e[22m" + faint "\e[02m" no-faint "\e[22m" + standout "\e[03m" no-standout "\e[23m" + underline "\e[04m" no-underline "\e[24m" + blink "\e[05m" no-blink "\e[25m" + fast-blink "\e[06m" no-fast-blink "\e[25m" + reverse "\e[07m" no-reverse "\e[27m" + conceal "\e[08m" no-conceal "\e[28m" + strikethrough "\e[09m" no-strikethrough "\e[29m" + gothic "\e[20m" no-gothic "\e[22m" + double-underline "\e[21m" no-double-underline "\e[22m" + proportional "\e[26m" no-proportional "\e[50m" + overline "\e[53m" no-overline "\e[55m" + + no-border "\e[54m" + border-rectangle "\e[51m" no-border-rectangle "\e[54m" + border-circle "\e[52m" no-border-circle "\e[54m" + + no-ideogram-marking "\e[65m" + underline-or-right "\e[60m" no-underline-or-right "\e[65m" + double-underline-or-right "\e[61m" no-double-underline-or-right "\e[65m" + overline-or-left "\e[62m" no-overline-or-left "\e[65m" + double-overline-or-left "\e[63m" no-double-overline-or-left "\e[65m" + stress "\e[64m" no-stress "\e[65m" + + font-default "\e[10m" + font-first "\e[11m" no-font-first "\e[10m" + font-second "\e[12m" no-font-second "\e[10m" + font-third "\e[13m" no-font-third "\e[10m" + font-fourth "\e[14m" no-font-fourth "\e[10m" + font-fifth "\e[15m" no-font-fifth "\e[10m" + font-sixth "\e[16m" no-font-sixth "\e[10m" + font-seventh "\e[17m" no-font-seventh "\e[10m" + font-eigth "\e[18m" no-font-eigth "\e[10m" + font-ninth "\e[19m" no-font-ninth "\e[10m" +) + +FG[none]="$FX[none]" +BG[none]="$FX[none]" +colors=(black red green yellow blue magenta cyan white) +for color in {0..255}; do + if (( $color >= 0 )) && (( $color < $#colors )); then + index=$(( $color + 1 )) + FG[$colors[$index]]="\e[38;5;${color}m" + BG[$colors[$index]]="\e[48;5;${color}m" + fi + + FG[$color]="\e[38;5;${color}m" + BG[$color]="\e[48;5;${color}m" +done +unset color{s,} index diff --git a/modules/ssh/init.zsh b/modules/ssh/init.zsh new file mode 100644 index 0000000..f6a861e --- /dev/null +++ b/modules/ssh/init.zsh @@ -0,0 +1,38 @@ +# +# sets up ssh-agent +# + +# don't do anything unless we can actually use ssh-agent +if (( ! $+commands[ssh-agent] )); then + return 1 +fi + +local ssh_env=${TMPDIR:-/tmp}/ssh-agent.env +local ssh_sock=${TMPDIR:-/tmp}/ssh-agent.sock + +# start ssh-agent if not already running +if [[ ! -S ${SSH_AUTH_SOCK} ]]; then + # read environment if possible + source ssh_env 2> /dev/null + + if ! ps -U ${LOGNAME} -o pid,ucomm | grep -q -- "${SSH_AGENT_PID:--1} ssh-agent"; then + eval "$(ssh-agent | sed '/^echo /d' | tee ${ssh_env})" + fi +fi + +# create socket +if [[ -S ${SSH_AUTH_SOCKET} && ${SSH_AUTH_SOCKET} != ${ssh_sock} ]]; then + ln -sf ${SSH_AUTH_SOCKET} ${ssh_sock} + export SSH_AUTH_SOCK=${ssh_sock} +fi + +# load ids +if ssh-add -l 2>&1 | grep -q 'no identities'; then + if (( ${#zssh_ids} > 0 )); then + ssh-add "${HOME}/.ssh/${^zssh_ids[@]}" 2> /dev/null + else + ssh-add 2> /dev/null + fi +fi + +unset ssh_{sock,env} diff --git a/modules/syntax-highlighting/external b/modules/syntax-highlighting/external new file mode 160000 index 0000000..82f5eb1 --- /dev/null +++ b/modules/syntax-highlighting/external @@ -0,0 +1 @@ +Subproject commit 82f5eb17ecee1f18b3ce3d8a93761a51235cab78 diff --git a/modules/syntax-highlighting/init.zsh b/modules/syntax-highlighting/init.zsh new file mode 100644 index 0000000..ffcba92 --- /dev/null +++ b/modules/syntax-highlighting/init.zsh @@ -0,0 +1,8 @@ +# +# enables fish-shell like syntax highlighting +# + +source "${0:h}/external/zsh-syntax-highlighting.zsh" || return 1 + +# highlighters +ZSH_HIGHLIGHT_HIGHLIGHTERS=(${zhighlighters[@]}) diff --git a/modules/utility/init.zsh b/modules/utility/init.zsh new file mode 100644 index 0000000..6974923 --- /dev/null +++ b/modules/utility/init.zsh @@ -0,0 +1,30 @@ +# +# utility functions and options +# + +# general aliases +alias chmod='chmod --preserve-root -v' +alias chown='chown --preserve-root -v' + +# ls colors +if [[ dircolors ]]; then + if [[ -s ${HOME}/.dir_colors ]]; then + eval "$(dircolors --sh ${HOME}/.dir_colors)" + else + eval "$(dircolors --sh)" + fi + + alias ls='ls --group-directories-first --color=auto' + +else + export LSCOLORS='exfxcxdxbxGxDxabagacad' + export LS_COLORS='di=34:ln=35:so=32:pi=33:ex=31:bd=36;01:cd=33;01:su=31;40;07:sg=36;40;07:tw=32;40;07:ow=33;40;07:' + + alias ls='ls --group-directories-first -G' +fi + +alias l='ls -lAh' # one column, all files, human-readable sizes + +# resource usage +alias df='df -kh' +alias du='du -kh' diff --git a/templates/zimrc b/templates/zimrc new file mode 100644 index 0000000..73111b8 --- /dev/null +++ b/templates/zimrc @@ -0,0 +1,50 @@ +################# +# CORE SETTINGS # +################# + +# +# Zim settings +# + +# select what modules you would like enabled +zmodules=(completion directory environment git history ssh utility \ + syntax-highlighting history-substring-search prompt) + + +################### +# MODULE SETTINGS # +################### + +# +# Prompt +# + +# set your desired prompt here +zprompt_theme='agnoster' + + +# +# zsh-syntax-highlighting +# + +# this determines what highlighters will be used with the completion module +zhighlighters=(main brackets cursor) + + +# +# SSH +# + +# load these ssh identities with the ssh module +zssh_ids=(id_rsa) + + +# +# Pacman +# + +# set (optional) pacman front-end. If not set, zim will attempt to use powerpill or pacmatic if available +#zpacman_frontend='powerpill' + +# load any helper scripts as difined here +#zpacman_helper=(aur) diff --git a/templates/zlogin b/templates/zlogin new file mode 100644 index 0000000..da7defa --- /dev/null +++ b/templates/zlogin @@ -0,0 +1,59 @@ +# +# startup file read in interactive login shell +# not run again in subsuquent shells +# + +# The following code helps us by optimizing the existing framework. +# This includes zcompile, zcompdump, etc. Options can be adjusted in .zimrc +# + +# Function to determine the need of a zcompile. If the .zwc file +# does not exist, or the base file is newer, we need to compile. +local zcompare() { + if [[ -s ${1} && ( ! -s ${1}.zwc || ${1} -nt ${1}.zwc) ]]; then + # needs zcomplie + zcompile ${1} + return 0 + else + # no need to zcompile + return 1 + fi +} + +# These jobs are asynchronous, and will not impact the interactive shell +{ + # First, we will zcompile the completion cache, if it exists. Siginificant speedup. + zcompare ${ZDOTDIR:-$HOME}/.zcompdump + + # Next, we should zcomplie the 'heavy' modules where possible. + # This includes syntax-highlighting and completion. + # Other modules may be added to this list at a later date. + function { + # use of anonymous function for setopt extended_glob + + local zim=${ZDOTDIR:-$HOME}/.zim + setopt EXTENDED_GLOB + + # + # syntax-highlighting zcompile + # + if [[ -d ${zim}/modules/syntax-highlighting/external/highlighters ]]; then + # compile the highlighters + for file in ${zim}/modules/syntax-highlighting/external/highlighters/**/*.zsh; do + zcompare ${file} + done + # compile the main file + zcompare ${zim}/modules/syntax-highlighting/external/zsh-syntax-highlighting.zsh + fi + + # + # zsh-histery-substring-search zcompile + # + if [[ -s ${zim}/modules/zsh-history-substring-search/external/zsh-history-substring-search.zsh ]]; then + zcompare ${zim}/modules/zsh-history-substring-search/external/zsh-history-substring-search.zsh + fi + } + +} &! + +unfunction zcompare diff --git a/templates/zshrc b/templates/zshrc new file mode 100644 index 0000000..80a24c1 --- /dev/null +++ b/templates/zshrc @@ -0,0 +1,9 @@ +# +# user configuration sourced by interactive shells +# + +# Source zim +if [[ -s ${ZDOTDIR:-$HOME}/.zim/init.zsh ]]; then + source ${ZDOTDIR:-$HOME}/.zim/init.zsh +fi +