Add basic XDG compliant sh architecture

The only file left in $HOME is .zshenv, which sets up zsh to source everything from XDG_CONFIG_HOME/zsh.
Shell files are split into sh and zsh directories, for global assignments (which should be posix compliant, work on any posix shell) like environemnt variables, xdg vars, and global aliases. zsh contains zsh specific customization (prompt customization, plugin loading, zsh completions).

Zsh initialization will pull from sh directory first, loading the respective mirror to its startup file (`.zprofile` loads `sh/profile` and `profile.d/*`, `.zshenv` loads `sh/env` and `sh/env.d/*` and `zsh/env.d/*`, `.zshrc` loads `sh/alias`, `sh/alias.d/*` and `zsh/alias.d/*`)

Once all is done, it will have loaded both global variables, aliases and settings, and zsh-only specifications. Other stow modules, if they want to add shell functionality, can include their aliases and functions in one of the above directories to automatically be picked up by zsh.
This commit is contained in:
Marty Oehme 2020-02-02 15:08:40 +00:00
parent a0a02be852
commit 6380affb6f
46 changed files with 1657 additions and 677 deletions

50
.gitignore vendored
View file

@ -1,50 +1,6 @@
*/.netrwhist
**/gopass-logo-small.png
# Created by https://www.gitignore.io/api/vim,linux
# Edit at https://www.gitignore.io/?templates=vim,linux
### Linux ###
*~
# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*
# KDE directory preferences
.directory
# Linux trash folder which might appear on any partition or disk
.Trash-*
# .nfs files are created when an open file is removed but is still being accessed
.nfs*
### Vim ###
# Swap
[._]*.s[a-v][a-z]
[._]*.sw[a-p]
[._]s[a-rt-v][a-z]
[._]ss[a-gi-z]
[._]sw[a-p]
# Session
Session.vim
Sessionx.vim
# Temporary
.netrwhist
# Auto-generated tag files
tags
# Persistent undo
[._]*.un~
# Coc configuration directory
.vim
# End of https://www.gitignore.io/api/vim,linux
# no idea why gopass adds this image to config path
gopass-logo-small.png
#
# Ignore dynamic colorschemes set by styler
colorscheme.vim
colorscheme

View file

@ -6,3 +6,6 @@
smudge = git-lfs smudge -- %f
process = git-lfs filter-process
required = true
[alias]
ignore = "!gitignore -f"
ign = "ignore"

View file

@ -1,12 +0,0 @@
export XDG_CONFIG_HOME="$HOME/.config"
# .zlogin
#
# load all files from .config/shell/login.d
if [ -d $XDG_CONFIG_HOME/shell/login.d ]; then
for file in $XDG_CONFIG_HOME/shell/login.d/*.sh; do
source $file
done
fi
export PATH="$HOME/.cargo/bin:$PATH"

6
home/.zshenv Normal file
View file

@ -0,0 +1,6 @@
#!/usr/bin/env zsh
#
# make zsh source the correct directory
export XDG_CONFIG_HOME=${XDG_CONFIG_HOME:-"$HOME/.config"}
ZDOTDIR="$XDG_CONFIG_HOME/zsh"

View file

@ -1,19 +0,0 @@
#!/bin/zsh
autoload zmv
if [ -d $XDG_CONFIG_HOME/shell/rc.d ]; then
for file in $XDG_CONFIG_HOME/shell/rc.d/*.sh; do
source $file
done
fi
if [ -d $XDG_CONFIG_HOME/shell/zshrc.d ]; then
for file in $XDG_CONFIG_HOME/shell/zshrc.d/*.zsh; do
source $file
done
fi

112
sh/.config/sh/alias Normal file
View file

@ -0,0 +1,112 @@
#!/usr/bin/env sh
#
# Global aliases for any shell
exist() { type "$1" >/dev/null 2>&1; }
# Avoid aliases which I did not create -- unalias EVERYTHING
unalias -a
# v shorthand for neovim
alias v="nvim"
# exit shell mimicks vim
alias :q="exit"
# ls defaults
if exist exa; then
alias l="exa -l --git --git-ignore"
alias L="exa -hal --grid --git"
# a recursive tree
# - usually want to change levels recursed with -L2 -L3 or similar
alias ll="exa --tree -L2"
alias LL="exa -a --tree -L2"
else
alias l="ls -lhF"
alias L="ls -lAhF"
fi
# cd defaults
alias ..="cd .."
alias ...="cd ../.."
alias ~="cd ~"
# git alias
if exist git; then
alias g='git'
alias ga='git add'
alias gaa='git add --all'
alias gb='git branch'
alias gbd='git branch -d'
alias gc='git commit -v'
alias gc!='git commit -v --amend'
alias gcn!='git commit -v --no-edit --amend'
alias gcm='git checkout master'
alias gcd='git checkout develop'
alias gcb='git checkout -b'
alias gco='git checkout'
alias gd='git diff'
alias gds='git diff --staged'
alias gi='git ignore'
alias glog='git log --stat'
alias glg='git log --oneline --decorate --graph'
alias glga='git log --oneline --decorate --graph --remotes --all'
alias glgp='git log --stat -p'
alias gf='git fetch'
alias gl='git pull'
alias gpn='git push --dry-run'
alias gp='git push'
alias gpf!='git push --force'
alias grv='git remote -v'
alias grs='git restore --staged'
alias grs!='git restore'
alias grbi='git rebase -i'
alias grbc='git rebase --continue'
alias gst='git status'
autoload -Uz is-at-least
if is-at-least 2.13 "$(git --version 2>/dev/null | awk '{print $3}')"; then
alias gsta='git stash push'
else
alias gsta='git stash save'
fi
alias gstp='git stash pop'
alias gstl='git stash list'
fi
# clear my screen
alias cl="clear"
# Display current external ip address
alias myip="curl -s icanhazip.com"
# fzf
if exist fzf; then
# Display fuzzy-searchable history
alias fzf_history="history | fzf --tac --height 20"
# Fuzzy search packages to install
if exist yay; then
alias fzf_yay="yay -Slq | fzf -m --preview 'yay -Si {1}' | xargs -ro yay -S"
# Fuzzy uninstall packages
alias fzf_yayrns="yay -Qeq | fzf -m --preview 'yay -Qi {1}' | xargs -ro yay -Rns"
fi
fi
# vifm
if exist vifm; then
alias vm=vifm
alias vmm='vifm ${PWD}'
# enable picture preview script
exist vifmrun && alias vifm=vifmrun
fi

44
sh/.config/sh/env Normal file
View file

@ -0,0 +1,44 @@
#!/usr/bin/env sh
#
# Set global environment variables
# Load XDG specifications
# shellcheck source=xdg
[ -f ~/.config/sh/xdg ] && . ~/.config/sh/xdg
# anything on BIN_HOME should be executable form anywhere
export PATH="$PATH:$XDG_BIN_HOME"
###############################
## BEGIN GLOBAL ENV VARS ##
###############################
# if we forgot to set it treat bash as default
export SHELL=${SHELL:-/bin/bash}
# will be picked up by many programs as notes directory
export WIKIROOT="${WIKIROOT:-$HOME/documents/notes}"
# will be picked up by many programs as library root directory
export LIBRARYROOT="${LIBRARYROOT:-$HOME/documents/library}"
# the default bibtex file to work on
# will change over time as primary projects change
# basically functions as 'default library' variable
export BIBFILE="${BIBFILE:-$LIBRARYROOT/academia/academia.bib}"
# these are my personal 'important' application settings
export EDITOR=nvim
export BROWSER=qutebrowser
export TERMINAL="alacritty"
export PAGER="less"
export FILEREADER="zathura"
export FILEMANAGER="vifm"
## gopath
export GOPATH="$HOME/projects/gopath/"
export PATH="$PATH:$GOPATH/bin"
## LANG LOCALE UTF-8
export LC_ALL="en_US.UTF-8"
export LANG="en_US.UTF-8"

18
sh/.config/sh/profile Normal file
View file

@ -0,0 +1,18 @@
#!/usr/bin/env sh
#
# Is executed for any base sh login-shell
# Bash only executes when neither bash-profile nor bashrc exist
# (will only load the first one it finds)
#
# see https://github.com/rbenv/rbenv/wiki/unix-shell-initialization
## Load all global environmment variables
# shellcheck source=env
[ -f ~/.config/sh/env ] && . ~/.config/sh/env
# load additional packages
if [ -d "$XDG_CONFIG_HOME/sh/env.d" ]; then
for _env in "$XDG_CONFIG_HOME/sh/env.d"/*.sh; do
. "$_env"
done
unset _env
fi

View file

@ -1,4 +1,4 @@
#!/bin/sh
#!/usr/bin/env sh
if [ ! "$DISPLAY" ] && [ "$XDG_VTNR" -eq 1 ]; then
exec startx "$XDG_CONFIG_HOME"/xresources/xinitrc

33
sh/.config/sh/xdg Normal file
View file

@ -0,0 +1,33 @@
#!/usr/bin/env sh
# XDG Base Directory Specification
#
# Sets up necessary environment variables for XDG convention,
# and those that applications obey for their environments.
#
# Thank you remeberYou for the idea
# see: https://github.com/rememberYou/dotfiles/blob/master/sh/.config/sh/xdg
#
# Additionally, home directories are set using the XDG specification,
# if the xdg-user-dirs module is enabled.
#
# Shellcheck will complain about setting permissions for the directories
# unless it is ignored https://github.com/koalaman/shellcheck/wiki/SC2174
# shellcheck disable=SC2174
# http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
test "$XDG_CACHE_HOME" || export XDG_CACHE_HOME="$HOME/.cache"
test "$XDG_CONFIG_HOME" || export XDG_CONFIG_HOME="$HOME/.config"
test "$XDG_DATA_HOME" || export XDG_DATA_HOME="$HOME/.local/share"
## Non-Standard additions
# non-standard, is added to path to enable execution of any files herein
test "$XDG_BIN_HOME" || export XDG_BIN_HOME="$HOME/.local/bin"
## ensure directories exist
test -d "$XDG_BIN_HOME" || mkdir -p -m 0700 "$XDG_BIN_HOME"
test -d "$XDG_CACHE_HOME" || mkdir -p -m 0700 "$XDG_CACHE_HOME"
test -d "$XDG_CONFIG_HOME" || mkdir -p -m 0700 "$XDG_CONFIG_HOME"
test -d "$XDG_DATA_HOME" || mkdir -p -m 0700 "$XDG_DATA_HOME"
## Applications that can be set through environment variables
export ZDOTDIR="$XDG_CONFIG_HOME/zsh"

View file

@ -1,16 +0,0 @@
#!/usr/bin/env sh
# important directories
# will be picked up by vim wiki plugin as root directory
export WIKIROOT="${WIKIROOT:-$HOME/documents/notes}"
export LIBRARYROOT="${LIBRARYROOT:-$HOME/documents/library}"
export BIBFILE="${BIBFILE:-$LIBRARYROOT/academia/academia.bib}"
# these are my personal 'important' environment settings
export EDITOR=nvim
export BROWSER=qutebrowser
export TERMINAL="alacritty"
export FILEREADER="zathura"
export FILEMANAGER="vifm"

View file

@ -1,8 +0,0 @@
#!/bin/sh
# these are mandatory for the shell to work
export XDG_CONFIG_HOME="$HOME/.config"
export XDG_CACHE_HOME="$HOME/.cache"
# these are my personal 'important' directories
export XDG_PROJECTS_DIR="$HOME/projects"

View file

@ -1,4 +0,0 @@
#!/bin/sh
export GOPATH="$HOME/projects/gopath/"
export PATH="$PATH:$GOPATH/bin"

View file

@ -1,5 +0,0 @@
#!/bin/sh
# put personal scripts on the PATH to be callable
PATH=$(du "$HOME"/.local/bin | cut -f2 | tr '\n' ':')$PATH
export PATH

View file

@ -1,65 +0,0 @@
# FIXME why is one saved with trailing "/" , the other not?
DEFAULT_NOTES="$HOME/documents/notes"
DEFAULT_LIB="$HOME/documents/library"
DEFAULT_BIB="$DEFAULT_LIB/academia/academia.bib"
setup() {
testfile="$BATS_TEST_DIRNAME/../env-vars.sh"
}
teardown() {
unset WIKIROOT
unset LIBRARYROOT
unset BIBFILE
}
@test "Populates WIKIROOT environment variable" {
source $testfile
[ -n "$WIKIROOT" ]
}
@test "Sets WIKIROOT to correct default path" {
source $testfile
echo $WIKIROOT
[ "$WIKIROOT" = "$DEFAULT_NOTES" ]
}
@test "Leaves WIKIROOT as is if it is already set" {
export WIKIROOT="MY/CUSTOM/DIR"
source $testfile
[ "$WIKIROOT" = "MY/CUSTOM/DIR" ]
}
@test "Populates LIBRARYROOT environment variable" {
source $testfile
[ -n "$LIBRARYROOT" ]
}
@test "Sets LIBRARYROOT to correct default path" {
source $testfile
echo $LIBRARYROOT
[ "$LIBRARYROOT" = "$DEFAULT_LIB" ]
}
@test "Leaves LIBRARYROOT as is if it is already set" {
export LIBRARYROOT="MY/CUSTOM/DIR"
source $testfile
[ "$LIBRARYROOT" = "MY/CUSTOM/DIR" ]
}
@test "Populates BIBFILE environment variable" {
source $testfile
[ -n "$BIBFILE" ]
}
@test "Sets BIBFILE to correct default path" {
source $testfile
echo $BIBFILE
[ "$BIBFILE" = "$DEFAULT_BIB" ]
}
@test "Leaves BIBFILE as is if it is already set" {
export BIBFILE="MY/CUSTOM/DIR"
source $testfile
[ "$BIBFILE" = "MY/CUSTOM/DIR" ]
}

View file

@ -1,37 +0,0 @@
#!/bin/sh
# Prettify ls commands
if [ "$(uname -s)" = "Linux" ]; then
# we're on linux
alias l-d="ls -lFad"
alias l="ls -lAhF" # Overwritten for k in -aliasing-k
alias ll="ls -lFa | TERM=vt100 less"
alias ls='ls --color=auto'
fi
# Show the top 5 commands used in recent history
_zhtop() {
history | awk "{a[\$2]++} END{for(i in a){printf \"%5d\t%s\n\",a[i],i}}" | sort -rn | head
}
alias zhtop=_zhtop
# Display timestamped recent command history
alias zh="fc -l -d -D"
# Display your current ip address
alias myip="curl -s icanhazip.com"
# move around faster for often used cd commands
alias ..="cd .." # overwritten by enhancd config in .zshrc.d/
alias ...="cd ../.."
alias ~="cd ~"
# make v call vim
alias v="vim"
# short, consise, clear my screen
alias cl="clear"
# let me exit out of the shell same way as vim
# TODO integrate session management with w?
alias :q="exit"
alias :wq="exit"

View file

@ -1,83 +0,0 @@
#!/bin/sh
# check for existence of fuzzy finders. If found, substitute fzf with it.
# order is skim > fzy > fzf > nothing
if type sk >/dev/null 2>&1; then
alias fzf=sk
elif type fzy >/dev/null 2>&1; then
alias fzf=fzy
elif type fzf >/dev/null 2>&1; then
alias fzf=fzf
else
echo "[WARNING]: No fuzzy finder found - install skim/fzf/fzy to enable functionality"
fi
# check for existence of greplikes. If found, substitute fzf with it.
# order is skim > fzy > fzf > nothing
if type rg >/dev/null 2>&1; then
alias rg=rg
elif type ag >/dev/null 2>&1; then
alias rg=ag
elif type ack >/dev/null 2>&1; then
alias rg=ack
else
echo "[WARNING]: No grep-like found - install ripgrep/the silver surfer (ag)/ack to enable functionality"
fi
# TODO Allow yanking of urls, c-e to open in editor, preview window with a-p and more
# FZF FILES AND FOLDERS
fzf_cd_weighted() {
cd "$(fasd -d | sk --nth=1 --with-nth=2 --tac | cut -d' ' -f2- | sed 's/^[ \t]*//;s/[\t]*$//')" || echo "cd not successful"
}
fzf_cd_all() {
cd "$(sk --cmd 'find / -type d -not \( -path /proc -prune \)')" || echo "cd not successful"
}
fzf_files_weighted() {
xdg-open "$(fasd -f | sk --nth=1 --with-nth=2 --tac | cut -d' ' -f2- | sed 's/^[ \t]*//;s/[\t]*$//')" || echo "xdg-open not successful"
}
fzf_files_all() {
xdg-open "$(sk --cmd 'find / -type d -not \( -path /proc -prune \)')" || echo "xdg-open not successful"
}
fzf_mru_weighted() {
target="$(fasd -t | sk --nth=1 --with-nth=2 --tac | cut -d' ' -f2- | sed 's/^[ \t]*//;s/[\t]*$//')"
if [ -f "$target" ]; then
xdg-open "$target" || echo "xdg-open not successful"
elif [ -d "$target" ]; then
cd "$target" || echo "cd not successful"
fi
}
# FZF NOTES
fzf_notes() {
sk --cmd "command rg --follow --ignore-case --line-number --color never --no-messages --no-heading --with-filename '' /home/marty/Nextcloud/Notes" --ansi --multi --tiebreak='length,begin' --delimiter=':' --with-nth=3.. --preview='cat {1}' --preview-window=:wrap
}
# FZF BIBTEX REFERENCES
fzf_bibtex() {
target=$(sk --cmd "bibtex-ls -cache $XDG_CACHE_HOME ~/Nextcloud/Library/academia/academia.bib" --ansi --with-nth=.. --preview-window=:wrap --prompt "Citation> " --preview="papis edit -e cat ref=$(echo {} | bibtex-cite | sed 's/^@//')")
papis edit ref="$(echo "$target" | bibtex-cite | sed 's/^@//')"
}
# set up fuzzy file and directory search
alias f=fzf_files_weighted
alias F=fzf_files_all
alias d=fzf_cd_weighted
alias D=fzf_cd_all
alias ru=fzf_mru_weighted
# set up fuzzy bibtex reference search
alias ref=fzf_bibtex
# Display fuzzy-searchable history
alias zhfind="history | fzf --tac --height 20"
# Fuzzy search packages to install
alias fzay="yay -Slq | fzf -m --preview 'yay -Si {1}' | xargs -ro yay -S"
# Fuzzy uninstall packages
alias uzay="yay -Qeq | fzf -m --preview 'yay -Qi {1}' | xargs -ro yay -Rs"

View file

@ -1,4 +0,0 @@
#!/bin/sh
# Check for existence of nvim command. If found, substitute vim with it.
type nvim >/dev/null 2>&1 && alias vim=nvim

View file

@ -1,8 +0,0 @@
#!/bin/sh
if type wal >/dev/null 2>&1; then
alias sd="wal --theme gruvbox" # grubbox dark
alias sD="wal --theme vscode" # pencil-like dark theme
alias sl="wal --theme base16-gruvbox-medium -l" # pencil-like light theme
alias sL="wal --theme 3024 -l" # pencil-like light theme
fi

View file

@ -1,10 +0,0 @@
#!/bin/sh
# Check for existence of vifm command. If found, substitute vifm with it.
type vifm >/dev/null 2>&1 && alias vm=vifm
# if vifm exists, also let me open current dir in vifm with vmm
type vifm >/dev/null 2>&1 && alias vmm='vifm ${PWD}'
# Check for existence of vifmrun command. If found, substitute vifm with it.
type vifmrun >/dev/null 2>&1 && alias vifm=vifmrun

View file

@ -1,6 +0,0 @@
#!/bin/sh
# if wal exists
# Import colorscheme from 'wal' asynchronously
# & # Run the process in the background.
# ( ) # Hide shell job control messages.
type wal >/dev/null 2>&1 && (cat ~/.cache/wal/sequences &)

View file

@ -1,4 +0,0 @@
#!/bin/sh
export LC_ALL="en_US.utf-8"
export LANG="en_US.utf-8"

View file

@ -1,15 +0,0 @@
setup() {
testfile="$BATS_TEST_DIRNAME/../locale-utf-8.sh"
}
teardown() {
export LC_ALL=""
export LANG=""
}
@test "Sets LC_ALL and LANG to en_US.utf-8" {
source $testfile
expected="en_US.utf-8"
[ "$LC_ALL" = "en_US.utf-8" ]
[ "$LANG" = "en_US.utf-8" ]
}

View file

@ -1,28 +0,0 @@
#!/bin/zsh
### Set ZSH History defaults
# set some history options
setopt append_history
setopt extended_history
setopt hist_expire_dups_first
setopt hist_ignore_all_dups
setopt hist_ignore_dups
setopt hist_ignore_space
setopt hist_reduce_blanks
setopt hist_save_no_dups
setopt hist_verify
# Share your history across all your terminal windows
setopt share_history
#setopt noclobber
# set some more options
setopt pushd_ignore_dups
#setopt pushd_silent
# Keep a ton of history.
export HISTSIZE=100000
export SAVEHIST=100000
HISTFILE=~/.zsh_history
export HISTIGNORE="ls:cd:cd -:pwd:exit:date:* --help"

View file

@ -1,16 +0,0 @@
#!/bin/zsh
#
# Expand aliases inline - see http://blog.patshead.com/2012/11/automatically-expaning-zsh-global-aliases---simplified.html
globalias() {
if [[ $LBUFFER =~ [A-Z0-9]+$ ]]; then
zle _expand_alias
zle expand-word
fi
zle self-insert
}
zle -N globalias
bindkey " " globalias
bindkey "^ " magic-space # control-space to bypass completion
bindkey -M isearch " " magic-space # normal space during searches

View file

@ -1,123 +0,0 @@
#!/bin/zsh
# Clone zgen if you haven't already
check_zgen_installation() {
if [[ -z "$ZGEN_PARENT_DIR" ]]; then
ZGEN_PARENT_DIR=${XDG_CONFIG_HOME:="$HOME/.config/"}
ZGEN_DIR="$ZGEN_PARENT_DIR/zgen"
fi
if [[ ! -f $ZGEN_DIR/zgen.zsh ]]; then
if [[ ! -d "$ZGEN_PARENT_DIR" ]]; then
mkdir -p "$ZGEN_PARENT_DIR"
fi
cd "$ZGEN_PARENT_DIR" || return
git clone https://github.com/tarjoilija/zgen.git "$ZGEN_DIR"
fi
# shellcheck source=/home/marty/.config/zgen/zgen.zsh
# shellcheck disable=SC1091
source "$ZGEN_DIR"/zgen.zsh
unset ZGEN_PARENT_DIR
}
load_plugins() {
ZGEN_LOADED=()
ZGEN_COMPLETIONS=()
zgen oh-my-zsh
# If you want to customize your plugin list, create a file named
# .zgen-local-plugins in your home directory. That file will be sourced
# during startup *instead* of running this load-starter-plugin-list function,
# so make sure to include everything from this function that you want to keep.
# If zsh-syntax-highlighting is bundled after zsh-history-substring-search,
# they break, so get the order right.
zgen load zdharma/fast-syntax-highlighting
zgen load zsh-users/zsh-history-substring-search
# Set keystrokes for substring searching
zmodload zsh/terminfo
bindkey "${terminfo[kcuu1]:?}" history-substring-search-up
bindkey "${terminfo[kcud1]:?}" history-substring-search-down
# Automatically run zgen update and zgen selfupdate every 7 days.
zgen load unixorn/autoupdate-zgen
# Warn you when you run a command that you've set an alias for without
# using the alias.
zgen load djui/alias-tips
# Colorize the things if you have grc installed. Well, some of the
# things, anyway.
zgen load unixorn/warhol.plugin.zsh
zgen load chrissicool/zsh-256color
# Add Fish-like autosuggestions to your ZSH.
zgen load zsh-users/zsh-autosuggestions
# Bullet train prompt setup.
zgen load bhilburn/powerlevel9k powerlevel9k
# automatically sources (known/whitelisted) .autoenv.zsh files
# as long as you're in the folder (and can optionally 'unsource' on leaving)
zgen load Tarrasch/zsh-autoenv
# radically enhanced cd command, all sorts of options
zgen load b4b4r07/enhancd
# set up nvm, the npm version manager
zgen load lukechilds/zsh-nvm
# Add git helper scripts.
zgen load unixorn/git-extra-commands
# Tom Limoncelli's tooling for storing private information (keys, etc)
# in a repository securely by encrypting them with gnupg.
zgen load StackExchange/blackbox
# Load some oh-my-zsh plugins
zgen oh-my-zsh plugins/pip
zgen oh-my-zsh plugins/sudo
zgen oh-my-zsh plugins/aws
zgen oh-my-zsh plugins/chruby
zgen oh-my-zsh plugins/colored-man-pages
zgen oh-my-zsh plugins/git
zgen oh-my-zsh plugins/github
zgen oh-my-zsh plugins/python
zgen oh-my-zsh plugins/rsync
zgen oh-my-zsh plugins/screen
zgen oh-my-zsh plugins/vagrant
# check for autojump install before applying plugin
if type autojump >/dev/null 2>&1; then
zgen oh-my-zsh plugins/autojump
fi
zgen oh-my-zsh plugins/tmux
zgen oh-my-zsh plugins/tmuxinator
# when in a directory with vagrant/docker files can use start, stop, up, down
zgen load Cloudstek/zsh-plugin-appup
# Load more completion files for zsh from the zsh-lovers github repo.
zgen load zsh-users/zsh-completions src
# Docker completion
zgen load srijanshetty/docker-zsh
# Very cool plugin that generates zsh completion functions for commands
# if they have getopt-style help text. It doesn't generate them on the fly,
# you'll have to explicitly generate a completion, but it's still quite cool.
zgen load RobSis/zsh-completion-generator
# Tab complete rakefile targets.
zgen load unixorn/rake-completion.zshplugin
# Load me last
GENCOMPL_FPATH=$HOME/.zsh/complete
zgen save
}
check_zgen_installation
if ! zgen saved; then
load_plugins
fi

View file

@ -1,12 +0,0 @@
#!/bin/zsh
# deal with screen, if we're using it - courtesy MacOSXHints.com
# Login greeting ------------------
if [ "$TERM" = "screen" ] && [ ! "$SHOWED_SCREEN_MESSAGE" = "true" ]; then
detached_screens=$(screen -list | grep Detached)
if [ -n "$detached_screens" ]; then
echo "+---------------------------------------+"
echo "| Detached screens are available: |"
echo "$detached_screens"
echo "+---------------------------------------+"
fi
fi

View file

@ -1,12 +0,0 @@
#!/bin/zsh
# Correct spelling for commands
setopt correct
# turn off the infernal correctall for filenames
unsetopt correctall
# Enable command auto-correction.
ENABLE_CORRECTION="true"
# Display red dots whilst waiting for completion.
COMPLETION_WAITING_DOTS="true"

View file

@ -1,5 +0,0 @@
#!/bin/zsh
# Long running processes should return time after they complete. Specified
# in seconds.
export REPORTTIME=2
export TIMEFMT="%U user %S system %P cpu %*Es total"

View file

@ -1,42 +0,0 @@
#!/bin/zsh
POWERLEVEL9K_MODE='nerdfont-complete'
#POWERLEVEL9K_SHORTEN_DIR_LENGTH=1
#POWERLEVEL9K_SHORTEN_DELIMITER=""
#POWERLEVEL9K_SHORTEN_STRATEGY="truncate_from_right"
POWERLEVEL9K_PROMPT_ON_NEWLINE=true
POWERLEVEL9K_LEFT_SEGMENT_SEPARATOR=''
POWERLEVEL9K_RIGHT_SEGMENT_SEPARATOR=''
POWERLEVEL9K_LEFT_SUBSEGMENT_SEPARATOR=''
POWERLEVEL9K_RIGHT_SUBSEGMENT_SEPARATOR=''
POWERLEVEL9K_MULTILINE_FIRST_PROMPT_PREFIX="%F{blue}\u256D\u2500%F{white}"
POWERLEVEL9K_MULTILINE_LAST_PROMPT_PREFIX="%F{blue}\u2570\uf460%F{white} "
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(root_indicator dir dir_writable_joined)
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(command_execution_time
vcs background_jobs_joined time_joined)
POWERLEVEL9K_VCS_MODIFIED_BACKGROUND="clear"
POWERLEVEL9K_VCS_UNTRACKED_BACKGROUND="clear"
POWERLEVEL9K_VCS_MODIFIED_FOREGROUND="yellow"
POWERLEVEL9K_VCS_UNTRACKED_FOREGROUND="yellow"
POWERLEVEL9K_DIR_HOME_BACKGROUND="clear"
POWERLEVEL9K_DIR_HOME_FOREGROUND="blue"
POWERLEVEL9K_DIR_HOME_SUBFOLDER_BACKGROUND="clear"
POWERLEVEL9K_DIR_HOME_SUBFOLDER_FOREGROUND="blue"
POWERLEVEL9K_DIR_WRITABLE_FORBIDDEN_BACKGROUND="clear"
POWERLEVEL9K_DIR_WRITABLE_FORBIDDEN_FOREGROUND="red"
POWERLEVEL9K_DIR_DEFAULT_BACKGROUND="clear"
POWERLEVEL9K_DIR_DEFAULT_FOREGROUND="white"
POWERLEVEL9K_ROOT_INDICATOR_BACKGROUND="red"
POWERLEVEL9K_ROOT_INDICATOR_FOREGROUND="white"
POWERLEVEL9K_STATUS_OK_BACKGROUND="clear"
POWERLEVEL9K_STATUS_OK_FOREGROUND="green"
POWERLEVEL9K_STATUS_ERROR_BACKGROUND="clear"
POWERLEVEL9K_STATUS_ERROR_FOREGROUND="red"
POWERLEVEL9K_TIME_BACKGROUND="clear"
POWERLEVEL9K_TIME_FOREGROUND="cyan"
POWERLEVEL9K_COMMAND_EXECUTION_TIME_BACKGROUND='clear'
POWERLEVEL9K_COMMAND_EXECUTION_TIME_FOREGROUND='magenta'
POWERLEVEL9K_BACKGROUND_JOBS_BACKGROUND='clear'
POWERLEVEL9K_BACKGROUND_JOBS_FOREGROUND='green'
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=250"

View file

@ -1,20 +0,0 @@
#!/bin/zsh
#
# Clone tmux plugin manager if not existing
if [[ -z "$TPM_PARENT_DIR" ]]; then
TPM_PARENT_DIR=${XDG_CONFIG_HOME:-$HOME/.config}/tmux
fi
if [[ ! -f $TPM_PARENT_DIR/plugins/tpm/tpm ]]; then
if [[ ! -d "$TPM_PARENT_DIR" ]]; then
mkdir -p "$TPM_PARENT_DIR"
fi
cd "$TPM_PARENT_DIR" || exit
git clone https://github.com/tmux-plugins/tpm plugins/tpm
fi
export TMUX_PLUGIN_MANAGER_PATH=$TPM_PARENT_DIR/plugins
alias tmux="tmux -f "'"${TPM_PARENT_DIR}"'"/tmux.conf"
unset TPM_PARENT_DIR
unset TPM_SUB_DIR

View file

@ -1,8 +0,0 @@
#!/bin/zsh
# uses exa in detail mode
alias l="exa -l --git --git-ignore"
# shows hidden files
alias L="exa -hal --grid --git"
# a recursive tree - usually want to change levels recused with -L2 -L3 or similar
alias ll="exa --tree -L2"
alias LL="exa -a --tree -L2"

View file

@ -1,5 +0,0 @@
#!/bin/zsh
# mkdir & cd
function mkcd() {
mkdir -p "$@" && cd "$_" || return
}

View file

@ -1,10 +0,0 @@
#!/bin/zsh
# show newest files
# http://www.commandlinefu.com/commands/view/9015/find-the-most-recently-changed-files-recursively
newest() {
find . -type f -printf '%TY-%Tm-%Td %TT %p\n' |
grep -v cache |
grep -v '.hg' | grep -v '.git' |
sort -r |
less
}

View file

@ -1,6 +0,0 @@
#!/bin/zsh
# automatically use tmux whenever we ssh to a server
function ssht() {
ssh "$@" -t 'tmux a || tmux || /bin/bash'
}

View file

@ -1,16 +0,0 @@
#!/bin/zsh
#
# Speed up autocomplete, force prefix mapping
zstyle ':completion:*' accept-exact '*(N)'
zstyle ':completion:*' use-cache on
zstyle ':completion:*' cache-path ~/.zsh/cache
# shellcheck disable=SC2016
zstyle -e ':completion:*:default' list-colors 'reply=("${PREFIX:+=(#bi)($PREFIX:t)*==34=34}:${(s.:.)LS_COLORS}")'
# Load any custom zsh completions we've installed
if [ -d ~/.zsh-completions ]; then
for completion in ~/.zsh-completions/*; do
# shellcheck source=/dev/null
source "$completion"
done
fi

View file

@ -1,22 +0,0 @@
#!/bin/zsh
# shellcheck disable=SC2206
# shellcheck disable=SC2179
# shellcheck disable=SC2154
# In case a plugin adds a redundant path entry, remove duplicate entries
# from PATH
# from: https://unix.stackexchange.com/questions/40749/remove-duplicate-path-entries-with-awk-command
get_var() {
eval 'printf "%s\n" "${'"$1"'}"'
}
set_var() {
eval "$1=\"\$2\""
}
dedup_pathvar() {
pathvar_name="$1"
pathvar_value="$(get_var "$pathvar_name")"
deduped_path="$(perl -e 'print join(":",grep { not $seen{$_}++ } split(/:/, $ARGV[0]))' "$pathvar_value")"
set_var "$pathvar_name" "$deduped_path"
}
dedup_pathvar PATH
dedup_pathvar MANPATH

View file

@ -1,5 +0,0 @@
#!/bin/zsh
# Assumes enhancd is installed (via plugin)
# Let's you go back a directory with .. (usual cd .. behavior)
# Let's the enhancd backtrack menu appear with cd .. (usual enhancd behavior)
alias ..="ENHANCD_DISABLE_DOT=1 && cd .. && ENHANCD_DISABLE_DOT=0"

View file

@ -6,10 +6,11 @@
# absolute path. No other format is supported.
#
XDG_DESKTOP_DIR="$HOME/desktop"
XDG_DOWNLOAD_DIR="$HOME/downloads"
XDG_TEMPLATES_DIR="$HOME/templates"
XDG_PUBLICSHARE_DIR="$HOME/public"
XDG_DOCUMENTS_DIR="$HOME/documents"
XDG_DOWNLOAD_DIR="$HOME/downloads"
XDG_MUSIC_DIR="$HOME/music"
XDG_PICTURES_DIR="$HOME/pictures"
XDG_PROJECTS_DIR="$HOME/projects"
XDG_PUBLICSHARE_DIR="$HOME/public"
XDG_TEMPLATES_DIR="$HOME/templates"
XDG_VIDEOS_DIR="$HOME/videos"

1199
zsh/.config/zsh/.p10k._zsh Normal file

File diff suppressed because it is too large Load diff

19
zsh/.config/zsh/.zprofile Normal file
View file

@ -0,0 +1,19 @@
#!/usr/bin/env zsh
[ -f "$XDG_CONFIG_HOME/sh/profile" ] && . "$XDG_CONFIG_HOME/sh/profile"
# .zlogin
#
if [ -d "$XDG_CONFIG_HOME/sh/profile.d" ]; then
for file in "$XDG_CONFIG_HOME/sh/profile.d"/*.sh; do
# shellcheck disable=1090
source "$file"
done
unset file
fi
if [ -d "$XDG_CONFIG_HOME/zsh/profile.d" ]; then
for file in "$XDG_CONFIG_HOME/zsh/profile.d"/*.sh; do
# shellcheck disable=1090
source "$file"
done
unset file
fi

20
zsh/.config/zsh/.zshenv Normal file
View file

@ -0,0 +1,20 @@
#!/usr/bin/env zsh
#
#
# load global sh env vars
[ -f "$XDG_CONFIG_HOME/sh/env" ] && source "$XDG_CONFIG_HOME/sh/env"
if [ -d "$XDG_CONFIG_HOME/sh/env.d" ]; then
for _env in "$XDG_CONFIG_HOME/sh/env.d"/*.sh; do
. "$_env"
done
unset _env
fi
# load zsh specific env vars
if [ -d "$XDG_CONFIG_HOME/zsh/env.d" ]; then
for _env in "$XDG_CONFIG_HOME/zsh/env.d"/*.zsh; do
. "$_env"
done
unset _env
fi

125
zsh/.config/zsh/.zshrc Normal file
View file

@ -0,0 +1,125 @@
#!/usr/bin/env zsh
#
CONFDIR="${XDG_CONFIG_HOME:-$HOME/.config}"
ZSHCONFDIR="$CONFDIR/zsh"
# Set completion style
# The following lines were added by compinstall
zstyle ':completion:*' completer _complete _ignored _approximate
zstyle ':completion:*' list-colors ''
zstyle ':completion:*' matcher-list '' '+m:{[:lower:]}={[:upper:]} r:|[._-]=** r:|=**'
zstyle ':completion:*' menu select=1
zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s
zstyle :compinstall filename "$ZSHCONFDIR/.zshrc"
# End of lines added by compinstall
autoload -Uz compinit zmv
compinit
# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.config/zsh/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block, everything else may go below.
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi
# load all plugins
[ -f "$ZSHCONFDIR/plugins.zsh" ] && source "$ZSHCONFDIR/plugins.zsh"
# shellcheck source=alias
[ -f "$CONFDIR/sh/alias" ] && source "$CONFDIR/sh/alias"
# load additional aliases
if [ -d "$CONFDIR/sh/alias.d" ]; then
for _alias in "$CONFDIR/sh/alias.d"/*.sh; do
. "$_alias"
done
unset _alias
fi
if [ -d "$ZSHCONFDIR/alias.d" ]; then
for _alias in "$ZSHCONFDIR/alias.d"/*.sh; do
. "$_alias"
done
unset _alias
fi
# Correct spelling for commands
setopt correct
# turn off the infernal correctall for filenames
unsetopt correctall
# Enable command auto-correction.
ENABLE_CORRECTION="true"
# Speed up autocomplete, force prefix mapping
zstyle ':completion:*' accept-exact '*(N)'
zstyle ':completion:*' use-cache on
zstyle ':completion:*' cache-path "${XDG_CACHE_HOME:-$HOME/.cache}/zshcompcache"
# shellcheck disable=SC2016
zstyle -e ':completion:*:default' list-colors 'reply=("${PREFIX:+=(#bi)($PREFIX:t)*==34=34}:${(s.:.)LS_COLORS}")'
### history
## Set ZSH History defaults
setopt append_history
setopt extended_history
setopt hist_expire_dups_first
setopt hist_ignore_all_dups
setopt hist_ignore_dups
setopt hist_ignore_space
setopt hist_reduce_blanks
setopt hist_save_no_dups
setopt hist_verify
# Share your history across all your terminal windows
setopt share_history
setopt pushd_ignore_dups
#setopt pushd_silent
export HISTSIZE=100000
export SAVEHIST=100000
export HISTFILE="$XDG_DATA_HOME/zsh_history"
export HISTIGNORE="ls:cd:cd -:pwd:exit:date:* --help"
## Set ZSH History aliases
# Show the top 5 commands used in recent history
history_top() {
history | awk "{a[\$2]++} END{for(i in a){printf \"%5d\t%s\n\",a[i],i}}" | sort -rn | head
}
# Display timestamped recent command history
alias history="fc -l -d -D"
### Glob Alias expansion
# Expand aliases inline - see http://blog.patshead.com/2012/11/automatically-expaning-zsh-global-aliases---simplified.html
globalias() {
if [[ $LBUFFER =~ [A-Z0-9]+$ ]]; then
zle _expand_alias
zle expand-word
fi
zle self-insert
}
zle -N globalias
bindkey " " globalias
bindkey "^ " magic-space # control-space to bypass completion
bindkey -M isearch " " magic-space # normal space during searches
# Deduplicate PATH - remove any duplicate entries from PATH
# from: https://unix.stackexchange.com/questions/40749/remove-duplicate-path-entries-with-awk-command
get_var() {
eval 'printf "%s\n" "${'"$1"'}"'
}
set_var() {
eval "$1=\"\$2\""
}
dedup_pathvar() {
pathvar_name="$1"
pathvar_value="$(get_var "$pathvar_name")"
deduped_path="$(perl -e 'print join(":",grep { not $seen{$_}++ } split(/:/, $ARGV[0]))' "$pathvar_value")"
set_var "$pathvar_name" "$deduped_path"
}
dedup_pathvar PATH
dedup_pathvar MANPATH
# shellcheck is not built for zsh specific uses like p10k does
# so we remove it from being analyzed and linted in shellcheck by adding underscore
# To customize prompt, run `p10k configure` or edit ~/.config/zsh/.p10k.zsh.
[[ ! -f "$ZSHCONFDIR/.p10k._zsh" ]] || source "$ZSHCONFDIR/.p10k._zsh"
unset CONFDIR
unset ZSHCONFDIR

View file

@ -0,0 +1,70 @@
#!/bin/zsh
# Clone zgen if you haven't already
check_zgen_installation() {
if [[ -z "$ZGEN_PARENT_DIR" ]]; then
ZGEN_PARENT_DIR=${XDG_DATA_HOME:="$HOME/.local/share"}
ZGEN_DIR="$ZGEN_PARENT_DIR/zgen"
fi
if [[ ! -f $ZGEN_DIR/zgen.zsh ]]; then
if [[ ! -d "$ZGEN_PARENT_DIR" ]]; then
mkdir -p "$ZGEN_PARENT_DIR"
fi
cd "$ZGEN_PARENT_DIR" || return
git clone https://github.com/tarjoilija/zgen.git "$ZGEN_DIR"
fi
# shellcheck source=/home/marty/.config/zgen/zgen.zsh
# shellcheck disable=SC1091
source "$ZGEN_DIR"/zgen.zsh
unset ZGEN_PARENT_DIR
}
load_plugins() {
ZGEN_LOADED=()
ZGEN_COMPLETIONS=()
zgen oh-my-zsh
# If you want to customize your plugin list, create a file named
# .zgen-local-plugins in your home directory. That file will be sourced
# during startup *instead* of running this load-starter-plugin-list function,
# so make sure to include everything from this function that you want to keep.
# If zsh-syntax-highlighting is bundled after zsh-history-substring-search,
# they break, so get the order right.
zgen load zdharma/fast-syntax-highlighting
# zgen load zsh-users/zsh-history-substring-search
# # Set keystrokes for substring searching
# zmodload zsh/terminfo
# bindkey "${terminfo[kcuu1]:?}" history-substring-search-up
# bindkey "${terminfo[kcud1]:?}" history-substring-search-down
# Automatically run zgen update and zgen selfupdate every 7 days.
zgen load unixorn/autoupdate-zgen
# Warn you when you run a command that you've set an alias for without
# using the alias.
zgen load djui/alias-tips
# Add Fish-like autosuggestions to your ZSH.
zgen load zsh-users/zsh-autosuggestions
zgen load romkatv/powerlevel10k powerlevel10k
# radically enhanced cd command, all sorts of options
# zgen load b4b4r07/enhancd
# set up nvm, the npm version manager
zgen load lukechilds/zsh-nvm
zgen oh-my-zsh plugins/colored-man-pages
# Load me last
GENCOMPL_FPATH=${XDG_CONFIG_HOME:-"$HOME/.config/zsh"}/complete
zgen save
}
check_zgen_installation
if ! zgen saved; then
load_plugins
fi