inital commit
This commit is contained in:
+55
@@ -0,0 +1,55 @@
|
||||
#!/usr/bin/env zsh
|
||||
# ===============================================================
|
||||
# zlogin — Post-Startup Finalisation & Summary
|
||||
# ===============================================================
|
||||
|
||||
# --- Ensure environment ---
|
||||
#export DOTFILES="${DOTFILES:-$HOME/.dotfiles}"
|
||||
|
||||
#export outfile="${outfile:-$HOME/zshrc-log.json}"
|
||||
#LOGFILE="$outfile"
|
||||
|
||||
if [[ ! `typeset -f call_file` ]]; then
|
||||
source "$HOME/.dotfiles/bin/call_file"
|
||||
fi
|
||||
|
||||
# --- Execute all module .zlogin files dynamically ---
|
||||
zlogin_files=($DOTFILES/**/*.zlogin)
|
||||
for file in ${zlogin_files[@]}; do
|
||||
call_file "${file}" "zlogin"
|
||||
done
|
||||
|
||||
# --- Post-login environment tweaks ---
|
||||
export PIP_DISABLE_PIP_VERSION_CHECK=1
|
||||
|
||||
# --- Clean duplicate PATH entries ---
|
||||
typeset -U path
|
||||
PATH=${(Rj/:/)${(us/:/)PATH}:#* *}
|
||||
export PATH
|
||||
|
||||
if [[ "${GHOSTTY_QUICK_TERMINAL}" == 1 ]]; then
|
||||
eval ${QT_RUN}
|
||||
fi
|
||||
|
||||
# --- Timing summary from JSON log ---
|
||||
# if [[ -f "$LOGFILE" ]]; then
|
||||
# echo
|
||||
# echo "⏱ Startup Summary:"
|
||||
# if command -v jq >/dev/null 2>&1; then
|
||||
# jq -r '. | [.label, .duration_ms, .status, .file] | @tsv' "$LOGFILE" \
|
||||
# | column -t -s $'\t'
|
||||
# else
|
||||
# echo "(Install jq to parse $LOGFILE)"
|
||||
# fi
|
||||
# fi
|
||||
|
||||
# # --- Optional compdump refresh ---
|
||||
# [[ -f "$DOTFILES/zsh/compdump.zlogin" ]] && call_file "$DOTFILES/zsh/compdump.zlogin" "compdump"
|
||||
|
||||
# # Run completion diagnostics if failures logged
|
||||
# if grep -q '"label":"compinit".*"exit_code":[1-9]' "$HOME/zshrc-log.json" 2>/dev/null; then
|
||||
# echo "⚠️ Re-running compinit_doctor due to prior failure..."
|
||||
# ZSH_COMPLETION_DEBUG=1 source "$DOTFILES/zsh/compinit_doctor.zsh"
|
||||
# fi
|
||||
# zprof
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
export ZSH_COMPDUMP_AGE=7 # refresh cache every 7 days
|
||||
# export PATH="$PATH:/Users/ngorse/Library/Application Support/JetBrains/Toolbox/scripts"
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
zshenv.symlink
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
#!/usr/bin/env zsh
|
||||
# ===============================================================
|
||||
# zshrc — Dynamic Modular Config Loader with JSON Logging
|
||||
# ===============================================================
|
||||
|
||||
# Profiling
|
||||
[[ "$ZPROFRC" -ne 1 ]] || zmodload zsh/zprof
|
||||
alias zprofrc="ZPROFRC=1 zsh"
|
||||
typeset -g POWERLEVEL9K_INSTANT_PROMPT=false
|
||||
|
||||
# Ensure globals
|
||||
typeset -g DOTFILES="${DOTFILES:-$HOME/.dotfiles}"
|
||||
typeset -g outfile="${outfile:-$HOME/zshrc-log.json}"
|
||||
: > "$outfile" # clear old log
|
||||
|
||||
setopt EXTENDED_GLOB
|
||||
|
||||
if [[ ! `typeset -f call_file` ]]; then
|
||||
source "$DOTFILES/bin/call_file"
|
||||
fi
|
||||
|
||||
POWERLEVEL9K_INSTANT_PROMPT=true
|
||||
#if [[ -e "${HOME}/zsh-defer/zsh-defer.plugin.zsh" ]]; then
|
||||
# call_file ${HOME}/zsh-defer/zsh-defer.plugin.zsh
|
||||
#fi
|
||||
|
||||
|
||||
|
||||
# Use extended globbing syntax.
|
||||
|
||||
# load envrc from $HOME
|
||||
if [[ -a $HOME/.envrc ]];then
|
||||
call_file $HOME/.envrc "env"
|
||||
fi
|
||||
# load localrc from $HOME
|
||||
if [[ -a $HOME/.localrc ]];then
|
||||
call_file $HOME/.localrc "local"
|
||||
fi
|
||||
|
||||
if $POWERLEVEL9K_INSTANT_PROMPT; then
|
||||
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
|
||||
call_file "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" "instant"
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
unsetopt complete_aliases nobgnice
|
||||
typeset -U config_files
|
||||
config_files=($DOTFILES/**/*.zsh)
|
||||
|
||||
# --- PATH phase -------------------------------------------------
|
||||
for file in ${(M)config_files:#*/path.zsh}; do
|
||||
call_file "$file" "path"
|
||||
typeset -gU path
|
||||
done
|
||||
export -U PATH
|
||||
|
||||
# --- CONFIG phase ------------------------------------------------
|
||||
# exclude path.zsh, any *completion*.zsh, and the compinit driver itself
|
||||
for file in ${${${config_files:#*/path.zsh}:#*/*completion*.zsh}:#*/zsh/compinit.zsh}; do
|
||||
call_file "$file" # label auto-derives (dir for config.zsh, stem otherwise)
|
||||
done
|
||||
|
||||
# --- COMPLETION (cache-aware) -----------------------------------
|
||||
call_file "$DOTFILES/zsh/compinit.zsh" "compinit"
|
||||
|
||||
unset config_files
|
||||
|
||||
# Finish profiling by calling zprof.
|
||||
[[ "$ZPROFRC" -eq 1 ]] && zprof
|
||||
[[ -v ZPROFRC ]] && unset ZPROFRC
|
||||
|
||||
# Always return success
|
||||
true
|
||||
@@ -0,0 +1,85 @@
|
||||
# mask built-ins with better defaults
|
||||
alias ping='ping -c 5'
|
||||
if command -v nvim >/dev/null 2>&1; then
|
||||
alias vi=nvim
|
||||
alias vim=nvim
|
||||
fi
|
||||
alias grep="${aliases[grep]:-grep} --exclude-dir={.git,.vscode}"
|
||||
if command -v kitten >/dev/null 2>&1 && [[ -z "$SSH_CONNECTION" ]]; then
|
||||
alias s='foa(){ kitten ssh "$1" }; foa '
|
||||
elif command -v it2ssh >/dev/null 2>&1 && [[ -z "$SSH_CONNECTION" ]]; then
|
||||
alias s='foa(){ it2ssh "$1" }; foa '
|
||||
fi
|
||||
|
||||
# more ways to ls
|
||||
if command -v eza >/dev/null 2>&1; then
|
||||
alias ls='eza $eza_params'
|
||||
alias l='eza --git-ignore $eza_params'
|
||||
alias ll='eza --all --header --long $eza_params'
|
||||
alias llm='eza --all --header --long --sort=modified $eza_params'
|
||||
alias la='eza -lbhma --smart-group --hyperlink --icons=auto'
|
||||
alias lx='eza -lbhHigUmuSa@'
|
||||
alias lt='eza --tree $eza_params'
|
||||
alias tree='eza --tree $eza_params'
|
||||
elif command -v colorls >/dev/null 2>&1; then
|
||||
alias ls='colorls -A --sd --hyperlink --gs'
|
||||
alias ll='colorls -lA --sd'
|
||||
alias la='colorls -lAh --sd'
|
||||
fi
|
||||
alias lsa="ls -a"
|
||||
alias ldot='ls -ld .* --sd'
|
||||
|
||||
# disk usage
|
||||
alias df='df -H'
|
||||
# alias du='du -ch'
|
||||
# alias biggest='du -s ./* | sort -nr | awk '\''{print $2}'\'' | xargs du -sh'
|
||||
alias dux='du -x --max-depth=1 | sort -n'
|
||||
alias dud='du -d 1 -h'
|
||||
alias duf='du -sh *'
|
||||
|
||||
# misc
|
||||
alias please='sudo $(fc -ln -1)'
|
||||
alias zshrc='${EDITOR:-nvim} "${ZDOTDIR:-$HOME}"/.zshrc'
|
||||
alias zbench='for i in {1..10}; do /usr/bin/time zsh -lic exit; done'
|
||||
alias cls="clear && printf '\e[3J'"
|
||||
|
||||
# print things
|
||||
alias print-fpath='echo -e ${FPATH//:/\\n}'
|
||||
alias print-path='echo -e ${PATH//:/\\n}'
|
||||
alias print-functions='print -l ${(k)functions[(I)[^_]*]} | sort'
|
||||
|
||||
alias rl!='exec zsh'
|
||||
alias packages='${EDITOR:-vim} $DOTFILES/antidote/zsh_plugins.txt'
|
||||
alias mkcd='foo(){ mkdir -p "$1"; cd "$1" }; foo '
|
||||
alias touchs='foa(){ touch "$1"; '${EDITOR:-vim}' "$1" }; foa '
|
||||
# alias touchs='foa(){ touch "$1"; subl "$1" }; foa '
|
||||
alias e='$EDITOR'
|
||||
alias lsub='$EDITOR $_'
|
||||
alias vl='less $_'
|
||||
alias cv='cat $_'
|
||||
alias ppip='noglob python -m pip'
|
||||
alias d='dirs -v | head -10'
|
||||
alias 1='cd -'
|
||||
alias 2='cd -2'
|
||||
alias 3='cd -3'
|
||||
alias 4='cd -4'
|
||||
alias 5='cd -5'
|
||||
alias 6='cd -6'
|
||||
alias 7='cd -7'
|
||||
alias 8='cd -8'
|
||||
alias 9='cd -9'
|
||||
# alias pwhich='pyenv which $_'
|
||||
alias wget='wget -c'
|
||||
alias mkdir='mkdir -p'
|
||||
alias mount='mount |column -t'
|
||||
#alias -g ±=~
|
||||
alias sess='${EDITOR} $HOME/.config/kitty/sessions/${DCS_PROJ_NAME:?error}.session'
|
||||
# alias zup='zplug update && zplug load --compile'
|
||||
# alias zinstall='zplug install && zplug load --compile'
|
||||
#alias -s {zsh,yml,conf}=o_vim
|
||||
alias lg=lazygit
|
||||
alias pan_id="foo(){ kitty @ ls --match-tab=state:self --match='cmdline:^vim' | jq '.[0].tabs[0].id' }; foo"
|
||||
alias clear_ssh='kitty @ action close_shared_ssh_connections'
|
||||
alias -g NE='2> /dev/null'
|
||||
alias -g NS='>/dev/null'
|
||||
alias -g NN='>/dev/null 2>&1'
|
||||
@@ -0,0 +1,138 @@
|
||||
#!/usr/bin/env zsh
|
||||
# ==================================================================
|
||||
# compinit.zsh — cache-aware completion init
|
||||
# - Fast path: compinit -C -d <dump> (skip rescans)
|
||||
# - Stale path: source *completion*.zsh (+ local rc), then compinit -i
|
||||
# ==================================================================
|
||||
|
||||
|
||||
|
||||
# ensure these options before compinit
|
||||
setopt complete_aliases nobgnice
|
||||
|
||||
# dump location + TTL
|
||||
local _zcomp_loc="${XDG_CACHE_HOME:-$HOME/.cache}/zcomp/zcompdump"
|
||||
if [[ "${ZSH_COMPDUMP}" != "${_zcomp_loc}" ]]; then
|
||||
typeset -g -r ZSH_COMPDUMP="${_zcomp_loc}"
|
||||
fi
|
||||
local _zcd="${ZSH_COMPDUMP:-$HOME/.cache/zcomp/zcompdump}"
|
||||
|
||||
# Guard if file missing
|
||||
#[[ ! -r "$ZSH_COMPDUMP" ]] && {
|
||||
# print -u2 "comp_init: missing or unreadable: $ZSH_COMPDUMP"
|
||||
# return 1
|
||||
#}
|
||||
local ZCOMP_TTL_HOURS="${ZCOMP_TTL_HOURS:-20}"
|
||||
typeset -g ZCOMP_DUMP_PATH=${ZSH_COMPDUMP}
|
||||
|
||||
|
||||
# collect completion files from the already-built `config_files` list
|
||||
typeset -a _completion_files
|
||||
_completion_files=(${(M)${(@)config_files}:#*/*completion*.zsh})
|
||||
|
||||
# fallback if compinit.zsh is called standalone (no `config_files` in scope)
|
||||
(( ${#_completion_files} == 0 )) && _completion_files=($DOTFILES/**/*completion*.zsh(N))
|
||||
|
||||
# include local additions if present
|
||||
local _have_local_comp=0
|
||||
[[ -e "$HOME/.local_comp_rc" ]] && _have_local_comp=1
|
||||
|
||||
# fast if either dump or compiled dump fresher than TTL hours
|
||||
local _fast=0
|
||||
if [[ ${_zcd}(#qNmh-${ZCOMP_TTL_HOURS}) || ${_zcd}.zwc(#qNmh-${ZCOMP_TTL_HOURS}) ]]; then
|
||||
_fast=1
|
||||
fi
|
||||
|
||||
autoload -U compinit
|
||||
|
||||
if (( _fast )); then
|
||||
compinit -C -d "$_zcd"
|
||||
else
|
||||
(( _have_local_comp )) && source "$HOME/.local_comp_rc"
|
||||
local f
|
||||
for f in "${_completion_files[@]}"; do
|
||||
call_file "$f" "${f:h:t}"
|
||||
done
|
||||
compinit -i -d "$_zcd"
|
||||
{ zcompile "$_zcd" 2>/dev/null } &!
|
||||
fi
|
||||
|
||||
unset _zcd _completion_files _fast _have_local_comp ZCOMP_TTL_HOURS
|
||||
|
||||
_comp_options+=(globdots) # With hidden files
|
||||
if [[ ! $(command -v antidote) ]] && [[ -d $DOTFILES/oh-my-zsh ]]; then
|
||||
call_file $DOTFILES/oh-my-zsh/completion.zsh "omz-comp"
|
||||
fi
|
||||
|
||||
|
||||
|
||||
# +---------+
|
||||
# | Options |
|
||||
# +---------+
|
||||
|
||||
# setopt GLOB_COMPLETE # Show autocompletion menu with globs
|
||||
setopt MENU_COMPLETE # Automatically highlight first element of completion menu
|
||||
setopt AUTO_LIST # Automatically list choices on ambiguous completion.
|
||||
setopt COMPLETE_IN_WORD # Complete from both ends of a word.
|
||||
|
||||
# Define completers
|
||||
zstyle ':completion:*' completer _extensions _complete _dynamic_directory_name _ignored
|
||||
|
||||
# Use cache for commands using cache
|
||||
zstyle ':completion:*' use-cache on
|
||||
zstyle ':completion:*' cache-path ${ZSH_COMPDUMP:h}
|
||||
# Complete the alias when _expand_alias is used as a function
|
||||
zstyle ':completion:*' complete true
|
||||
|
||||
zle -C alias-expension complete-word _generic
|
||||
bindkey '^Xa' alias-expension
|
||||
zstyle ':completion:alias-expension:*' completer _expand_alias
|
||||
|
||||
# Use cache for commands which use it
|
||||
|
||||
# Allow you to select in a menu
|
||||
zstyle ':completion:*' menu select
|
||||
|
||||
# Autocomplete options for cd instead of directory stack
|
||||
zstyle ':completion:*' complete-options false
|
||||
|
||||
zstyle ':completion:*' file-sort modification
|
||||
|
||||
|
||||
zstyle ':completion:*:*:*:*:corrections' format '%F{yellow}!- %d (errors: %e) -!%f'
|
||||
zstyle ':completion:*:*:*:*:descriptions' format '%F{blue}-- %D %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'
|
||||
# Colors for files and directory
|
||||
zstyle ':completion:*:*:*:*:default' list-colors ${(s.:.)LS_COLORS}
|
||||
# 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 'dynamic-directory-name' 'named-directories' 'path-directories' 'users' 'expand'
|
||||
|
||||
zstyle ':completion:*' squeeze-slashes true
|
||||
|
||||
# Ignore useless commands and functions
|
||||
zstyle ':completion:*:functions' ignored-patterns '(_*|pre(cmd|exec)|prompt_*)'
|
||||
zstyle ':completion:*:' ignored-patterns '(_*|pre(cmd|exec)|prompt_*)'
|
||||
|
||||
# Only display some tags for the command cd
|
||||
zstyle ':completion:*:*:cd:*' tag-order local-directories directory-stack path-directories
|
||||
# zstyle ':completion:*:complete:git:argument-1:' tag-order !aliases
|
||||
|
||||
# Required for completion to be in good groups (named after the tags)
|
||||
zstyle ':completion:*' group-name ''
|
||||
|
||||
zstyle ':completion:*:*:-command-:*:*' group-order aliases builtins functions commands
|
||||
|
||||
# See ZSHCOMPWID "completion matching control"
|
||||
zstyle ':completion:*' matcher-list '' 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
|
||||
|
||||
zstyle ':completion:*' keep-prefix true
|
||||
|
||||
zstyle -e ':completion:*:(ssh|scp|sftp|rsh|rsync):hosts' hosts 'reply=(${=${${(f)"$(cat {/etc/ssh_,~/.ssh/known_}hosts(|2)(N) /dev/null)"}%%[# ]*}//,/ })'
|
||||
|
||||
compctl -V directories -K _bd bd
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
|
||||
typeset -gU fpath
|
||||
|
||||
[[ -d /usr/share/zsh/5.9/functions ]] && fpath=(/usr/share/zsh/5.9/functions $fpath)
|
||||
[[ -d /usr/share/zsh/functions ]] && fpath=(/usr/share/zsh/5.9/functions $fpath)
|
||||
# fpath=($DOTFILES/zsh/plugins/zsh-completions/src $fpath)
|
||||
fpath=($(brew --prefix)/share/zsh/site-functions $fpath)
|
||||
|
||||
# Define excluded directory names (just names, not full paths)
|
||||
EXCLUDES=(zsh scripts bash vim zplug 00-homebrew iterm2 prettifer)
|
||||
|
||||
# Get all directories under DOTFILES
|
||||
dirs=(${DOTFILES}/*(/N))
|
||||
|
||||
# Loop through each exclusion and remove matches
|
||||
for ex in $EXCLUDES; do
|
||||
dirs=(${dirs:#${DOTFILES}/$ex})
|
||||
done
|
||||
|
||||
for topic_folder in $dirs; do
|
||||
if [ -d $topic_folder ]; then
|
||||
fpath=($topic_folder $fpath)
|
||||
fi
|
||||
done
|
||||
|
||||
autoload -U $DOTFILES/bin/*(:t)
|
||||
|
||||
export MANPATH="$HOME/.dotfiles/man:$MANPATH"
|
||||
@@ -0,0 +1,431 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Change directory and list files
|
||||
function cdl()
|
||||
{
|
||||
if [ -d "$@" ]; then
|
||||
cd "$@" && pwd ; ls;
|
||||
else
|
||||
echo "$@ doesn't exists."
|
||||
fi
|
||||
}
|
||||
|
||||
function chpwd()
|
||||
{
|
||||
if [[ $OSTYPE == linux* ]]; then
|
||||
ls --color=auto;
|
||||
elif [[ $OSTYPE == darwin* ]]; then
|
||||
ls -G
|
||||
else
|
||||
ls
|
||||
fi
|
||||
}
|
||||
|
||||
# Create a new directory and enter it
|
||||
function mkd() {
|
||||
mkdir -p "$@" && cd "$_";
|
||||
}
|
||||
|
||||
# Change working directory to the top-most Finder window location
|
||||
function cdf() { # short for `cdfinder`
|
||||
cd "$(osascript -e 'tell app "Finder" to POSIX path of (insertion location as alias)')";
|
||||
}
|
||||
|
||||
# Create a .tar.gz archive, using `zopfli`, `pigz` or `gzip` for compression
|
||||
function targz() {
|
||||
local tmpFile="${@%/}.tar";
|
||||
tar -cvf "${tmpFile}" --exclude=".DS_Store" "${@}" || return 1;
|
||||
|
||||
size=$(
|
||||
stat -f"%z" "${tmpFile}" 2> /dev/null; # macOS `stat`
|
||||
stat -c"%s" "${tmpFile}" 2> /dev/null; # GNU `stat`
|
||||
);
|
||||
|
||||
local cmd="";
|
||||
if (( size < 52428800 )) && hash zopfli 2> /dev/null; then
|
||||
# the .tar file is smaller than 50 MB and Zopfli is available; use it
|
||||
cmd="zopfli";
|
||||
else
|
||||
if hash pigz 2> /dev/null; then
|
||||
cmd="pigz";
|
||||
else
|
||||
cmd="gzip";
|
||||
fi;
|
||||
fi;
|
||||
|
||||
echo "Compressing .tar ($((size / 1000)) kB) using \`${cmd}\`…";
|
||||
"${cmd}" -v "${tmpFile}" || return 1;
|
||||
[ -f "${tmpFile}" ] && rm "${tmpFile}";
|
||||
|
||||
zippedSize=$(
|
||||
stat -f"%z" "${tmpFile}.gz" 2> /dev/null; # macOS `stat`
|
||||
stat -c"%s" "${tmpFile}.gz" 2> /dev/null; # GNU `stat`
|
||||
);
|
||||
|
||||
echo "${tmpFile}.gz ($((zippedSize / 1000)) kB) created successfully.";
|
||||
}
|
||||
|
||||
# Determine size of a file or total size of a directory
|
||||
function fs() {
|
||||
if du -b /dev/null > /dev/null 2>&1; then
|
||||
local arg=-sbh;
|
||||
else
|
||||
local arg=-sh;
|
||||
fi
|
||||
if [[ -n "$@" ]]; then
|
||||
du $arg -- "$@";
|
||||
else
|
||||
du $arg .[^.]* ./*;
|
||||
fi;
|
||||
}
|
||||
|
||||
# Use Git’s colored diff when available
|
||||
hash git &>/dev/null;
|
||||
if [ $? -eq 0 ]; then
|
||||
function diff() {
|
||||
git diff --no-index --color-words "$@";
|
||||
}
|
||||
fi;
|
||||
|
||||
# Create a data URL from a file
|
||||
function dataurl() {
|
||||
local mimeType=$(file -b --mime-type "$1");
|
||||
if [[ $mimeType == text/* ]]; then
|
||||
mimeType="${mimeType};charset=utf-8";
|
||||
fi
|
||||
echo "data:${mimeType};base64,$(openssl base64 -in "$1" | tr -d '\n')";
|
||||
}
|
||||
|
||||
# Create a git.io short URL
|
||||
function gitio() {
|
||||
if [ -z "${1}" -o -z "${2}" ]; then
|
||||
echo "Usage: \`gitio slug url\`";
|
||||
return 1;
|
||||
fi;
|
||||
curl -i https://git.io/ -F "url=${2}" -F "code=${1}";
|
||||
}
|
||||
|
||||
# Start an HTTP server from a directory, optionally specifying the port
|
||||
function server() {
|
||||
local port="${1:-8000}";
|
||||
sleep 1 && open "http://localhost:${port}/" &
|
||||
# Set the default Content-Type to `text/plain` instead of `application/octet-stream`
|
||||
# And serve everything as UTF-8 (although not technically correct, this doesn’t break anything for binary files)
|
||||
python -c $'import SimpleHTTPServer;\nmap = SimpleHTTPServer.SimpleHTTPRequestHandler.extensions_map;\nmap[""] = "text/plain";\nfor key, value in map.items():\n\tmap[key] = value + ";charset=UTF-8";\nSimpleHTTPServer.test();' "$port";
|
||||
}
|
||||
|
||||
# Start a PHP server from a directory, optionally specifying the port
|
||||
# (Requires PHP 5.4.0+.)
|
||||
function phpserver() {
|
||||
local port="${1:-4000}";
|
||||
local ip=$(ipconfig getifaddr en1);
|
||||
sleep 1 && open "http://${ip}:${port}/" &
|
||||
php -S "${ip}:${port}";
|
||||
}
|
||||
|
||||
# Compare original and gzipped file size
|
||||
function gz() {
|
||||
local origsize=$(wc -c < "$1");
|
||||
local gzipsize=$(gzip -c "$1" | wc -c);
|
||||
local ratio=$(echo "$gzipsize * 100 / $origsize" | bc -l);
|
||||
printf "orig: %d bytes\n" "$origsize";
|
||||
printf "gzip: %d bytes (%2.2f%%)\n" "$gzipsize" "$ratio";
|
||||
}
|
||||
|
||||
# Syntax-highlight JSON strings or files
|
||||
# Usage: `json '{"foo":42}'` or `echo '{"foo":42}' | json`
|
||||
function json() {
|
||||
if [ -t 0 ]; then # argument
|
||||
python -mjson.tool <<< "$*" | pygmentize -l javascript;
|
||||
else # pipe
|
||||
python -mjson.tool | pygmentize -l javascript;
|
||||
fi;
|
||||
}
|
||||
|
||||
# Run `dig` and display the most useful info
|
||||
function digga() {
|
||||
dig +nocmd "$1" any +multiline +noall +answer;
|
||||
}
|
||||
|
||||
# UTF-8-encode a string of Unicode symbols
|
||||
function escape() {
|
||||
printf "\\\x%s" $(printf "$@" | xxd -p -c1 -u);
|
||||
# print a newline unless we’re piping the output to another program
|
||||
if [ -t 1 ]; then
|
||||
echo ""; # newline
|
||||
fi;
|
||||
}
|
||||
|
||||
# Decode \x{ABCD}-style Unicode escape sequences
|
||||
function unidecode() {
|
||||
perl -e "binmode(STDOUT, ':utf8'); print \"$@\"";
|
||||
# print a newline unless we’re piping the output to another program
|
||||
if [ -t 1 ]; then
|
||||
echo ""; # newline
|
||||
fi;
|
||||
}
|
||||
|
||||
# Get a character’s Unicode code point
|
||||
function codepoint() {
|
||||
perl -e "use utf8; print sprintf('U+%04X', ord(\"$@\"))";
|
||||
# print a newline unless we’re piping the output to another program
|
||||
if [ -t 1 ]; then
|
||||
echo ""; # newline
|
||||
fi;
|
||||
}
|
||||
|
||||
# Show all the names (CNs and SANs) listed in the SSL certificate
|
||||
# for a given domain
|
||||
function getcertnames() {
|
||||
if [ -z "${1}" ]; then
|
||||
echo "ERROR: No domain specified.";
|
||||
return 1;
|
||||
fi;
|
||||
|
||||
local domain="${1}";
|
||||
echo "Testing ${domain}…";
|
||||
echo ""; # newline
|
||||
|
||||
local tmp=$(echo -e "GET / HTTP/1.0\nEOT" \
|
||||
| openssl s_client -connect "${domain}:443" -servername "${domain}" 2>&1);
|
||||
|
||||
if [[ "${tmp}" = *"-----BEGIN CERTIFICATE-----"* ]]; then
|
||||
local certText=$(echo "${tmp}" \
|
||||
| openssl x509 -text -certopt "no_aux, no_header, no_issuer, no_pubkey, \
|
||||
no_serial, no_sigdump, no_signame, no_validity, no_version");
|
||||
echo "Common Name:";
|
||||
echo ""; # newline
|
||||
echo "${certText}" | grep "Subject:" | sed -e "s/^.*CN=//" | sed -e "s/\/emailAddress=.*//";
|
||||
echo ""; # newline
|
||||
echo "Subject Alternative Name(s):";
|
||||
echo ""; # newline
|
||||
echo "${certText}" | grep -A 1 "Subject Alternative Name:" \
|
||||
| sed -e "2s/DNS://g" -e "s/ //g" | tr "," "\n" | tail -n +2;
|
||||
return 0;
|
||||
else
|
||||
echo "ERROR: Certificate not found.";
|
||||
return 1;
|
||||
fi;
|
||||
}
|
||||
|
||||
# `s` with no arguments opens the current directory in Sublime Text, otherwise
|
||||
# opens the given location
|
||||
function s() {
|
||||
if [ $# -eq 0 ]; then
|
||||
subl .;
|
||||
else
|
||||
subl "$@";
|
||||
fi;
|
||||
}
|
||||
|
||||
# `a` with no arguments opens the current directory in Atom Editor, otherwise
|
||||
# opens the given location
|
||||
function a() {
|
||||
if [ $# -eq 0 ]; then
|
||||
atom .;
|
||||
else
|
||||
atom "$@";
|
||||
fi;
|
||||
}
|
||||
|
||||
# `v` with no arguments opens the current directory in Vim, otherwise opens the
|
||||
# given location
|
||||
function v() {
|
||||
if [ $# -eq 0 ]; then
|
||||
vim .;
|
||||
else
|
||||
vim "$@";
|
||||
fi;
|
||||
}
|
||||
|
||||
# `o` with no arguments opens the current directory, otherwise opens the given
|
||||
# location
|
||||
function o() {
|
||||
if [ $# -eq 0 ]; then
|
||||
open .;
|
||||
else
|
||||
open "$@";
|
||||
fi;
|
||||
}
|
||||
|
||||
# `c` with no arguments opens the current directory in vscode, otherwise opens the
|
||||
# given location
|
||||
function c() {
|
||||
if [ $# -eq 0 ]; then
|
||||
code .;
|
||||
else
|
||||
code "$@";
|
||||
fi;
|
||||
}
|
||||
|
||||
# `tre` is a shorthand for `tree` with hidden files and color enabled, ignoring
|
||||
# the `.git` directory, listing directories first. The output gets piped into
|
||||
# `less` with options to preserve color and line numbers, unless the output is
|
||||
# small enough for one screen.
|
||||
function tre() {
|
||||
tree -aC -I '.git|node_modules|bower_components' --dirsfirst "$@" | less -FRNX;
|
||||
}
|
||||
|
||||
# Extract files
|
||||
function unpkg()
|
||||
{
|
||||
if [ -z "$1" ]; then
|
||||
# display usage if no parameters given
|
||||
echo "Usage: extract <path/file_name>.<zip|rar|bz2|gz|tar|tbz2|tgz|Z|7z|xz|ex|tar.bz2|tar.gz|tar.xz>"
|
||||
else
|
||||
if [ -f $1 ] ; then
|
||||
# NAME=${1%.*}
|
||||
# mkdir $NAME && cd $NAME
|
||||
case $1 in
|
||||
*.tar.bz2) tar xvjf $1 ;;
|
||||
*.tar.gz) tar xvzf $1 ;;
|
||||
*.tar.xz) tar xvJf $1 ;;
|
||||
*.lzma) unlzma $1 ;;
|
||||
*.bz2) bunzip2 $1 ;;
|
||||
*.rar) unrar x -ad $1 ;;
|
||||
*.gz) gunzip $1 ;;
|
||||
*.tar) tar xvf $1 ;;
|
||||
*.tbz2) tar xvjf $1 ;;
|
||||
*.tgz) tar xvzf $1 ;;
|
||||
*.zip) unzip $1 ;;
|
||||
*.Z) uncompress $1 ;;
|
||||
*.7z) 7z x $1 ;;
|
||||
*.xz) unxz $1 ;;
|
||||
*.exe) cabextract $1 ;;
|
||||
*) echo "extract: '$1' - unknown archive method" ;;
|
||||
esac
|
||||
else
|
||||
echo "$1 - file does not exist"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Go test and show coverage
|
||||
function gotest() {
|
||||
cached=""
|
||||
if [[ $1 == "-nocache" ]]; then
|
||||
cached="-count=1"
|
||||
shift
|
||||
fi
|
||||
if [ -z $1 ]; then
|
||||
go test ${cached} -cover -race ./...
|
||||
elif [ $1 = "-t" ]; then
|
||||
go test ${cached} -cover -race ./... | column -t
|
||||
elif [ $1 = "." ]; then
|
||||
go test ${cached} -v -race -coverprofile=profile.out -covermode=atomic
|
||||
elif [ $1 = "./..." ]; then
|
||||
echo 'mode: atomic' > profile.out
|
||||
go list ./... | xargs -I {} sh -c "go test ${cached} -race -coverprofile=profile.out.tmp -covermode=atomic {}; cat profile.out.tmp | tail -n +2 >> profile.out; rm profile.out.tmp"
|
||||
else
|
||||
go list ./... | grep --color=never $1 | xargs go test ${cached} -v -race -coverprofile=profile.out -covermode=atomic
|
||||
fi
|
||||
local exitCode=$?
|
||||
if [ -f profile.out ]; then
|
||||
go tool cover -func=profile.out
|
||||
rm profile.out
|
||||
fi
|
||||
return $exitCode
|
||||
}
|
||||
|
||||
function gotestcov() {
|
||||
go list ./... | grep --color=never $1 | xargs go test -count=1 -v -race -coverprofile=profile.out -covermode=atomic
|
||||
local exitCode=$?
|
||||
if [ -f profile.out ]; then
|
||||
go tool cover -func=profile.out
|
||||
go tool cover -html=profile.out
|
||||
rm profile.out
|
||||
fi
|
||||
return $exitCode
|
||||
}
|
||||
|
||||
function gobench() {
|
||||
local target=""
|
||||
if [ ! -z $1 ]; then
|
||||
target=./$1
|
||||
fi
|
||||
# go test -bench=${foo} -benchmem ./... 2>/dev/null | grep Benchmark | column -t
|
||||
go test -count=1 -benchmem -bench=. $target
|
||||
}
|
||||
|
||||
# E-Book Convert
|
||||
function epub2mobi() {
|
||||
if [ $# -eq 0 ]; then
|
||||
find . -name "*.epub" -exec ebook-convert {} {}.mobi \;
|
||||
else
|
||||
for epub in "$@"; do
|
||||
ebook-convert $epub ${epub}.mobi
|
||||
done
|
||||
fi
|
||||
find . -name "*.epub.mobi" -exec rename 's/\.epub\.mobi$/.mobi/' {} +
|
||||
}
|
||||
|
||||
|
||||
# List Docker Tags
|
||||
function dockertags() {
|
||||
if [ $# -lt 1 ]; then
|
||||
printf '%s\n' \
|
||||
"dockertags -- list all tags for a Docker image on Docker Hub registry." \
|
||||
"" \
|
||||
"EXAMPLE: " \
|
||||
" - list all tags for ubuntu:" \
|
||||
" ${0} ubuntu" \
|
||||
" - list all php tags containing apache:" \
|
||||
" ${0} php apache"
|
||||
return 1
|
||||
fi
|
||||
|
||||
image="$1"
|
||||
tags=`wget -q https://registry.hub.docker.com/v1/repositories/${image}/tags -O - | sed -e 's/[][]//g' -e 's/"//g' -e 's/ //g' | tr '}' '\n' | awk -F: '{print $3}'`
|
||||
|
||||
if [ -n "$2" ]; then
|
||||
tags=` echo "${tags}" | grep "$2" `
|
||||
fi
|
||||
|
||||
echo "${tags}"
|
||||
}
|
||||
|
||||
# VirtualEnv shortcuts
|
||||
export VIRTUAL_ENV_PATH="${HOME}/.virtualenvs/"
|
||||
function venv3() {
|
||||
if [ $# -eq 0 ]; then
|
||||
if [ ! -z ${VIRTUAL_ENV} ]; then
|
||||
echo $(basename ${VIRTUAL_ENV})
|
||||
fi
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [ $1 = "ls" ]; then
|
||||
ls $VIRTUAL_ENV_PATH
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [ $1 = "new" ]; then
|
||||
if [ ! -z $2 ]; then
|
||||
virtualenv -p python3 ${VIRTUAL_ENV_PATH}/$2
|
||||
fi
|
||||
else
|
||||
local ACTIVATE=${VIRTUAL_ENV_PATH}/$1/bin/activate
|
||||
if [ -f ${ACTIVATE} ]; then
|
||||
source ${ACTIVATE}
|
||||
else
|
||||
echo "$1 not exists"
|
||||
return 2
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Sync Git repo(s) of all direct subfolders
|
||||
function syncgits() {
|
||||
if [ -d .git ]; then
|
||||
git pull;
|
||||
else
|
||||
for entry in "."/*
|
||||
do
|
||||
if [[ -d "$entry" && -d "$entry/.git" ]]; then
|
||||
pushd "$entry"
|
||||
git pull
|
||||
popd
|
||||
fi
|
||||
done
|
||||
fi
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
updown_key() {
|
||||
bindkey "${terminfo[kcuu1]}" history-substring-search-up
|
||||
bindkey '\e[A' history-substring-search-up
|
||||
bindkey '\e[B' history-substring-search-down
|
||||
bindkey "${terminfo[kcud1]}" history-substring-search-down
|
||||
}
|
||||
|
||||
zmodload zsh/terminfo
|
||||
if [[ "$(antidote path zsh-users/zsh-history-substring-search 2> /dev/null)" ]]; then
|
||||
call_file "$(antidote path zsh-users/zsh-history-substring-search 2> /dev/null)/zsh-history-substring-search.zsh" "anti-hst-file"
|
||||
updown_key
|
||||
elif [[ -e "$ZSH_CUSTOM/plugins/zsh-history-substring-search/zsh-history-substring-search.zsh" ]]; then
|
||||
call_file $ZSH_CUSTOM/plugins/zsh-history-substring-search/zsh-history-substring-search.zsh "history substring" "substring-history"
|
||||
updown_key
|
||||
fi
|
||||
|
||||
HISTFILE=$HOME/.cache/.zsh_history
|
||||
SAVEHIST=100000
|
||||
HISTSIZE=100000
|
||||
HISTIGNORE=ls:ll:cd:pwd:..:...:htop:reload:r:la
|
||||
setopt inc_append_history
|
||||
setopt hist_ignore_all_dups
|
||||
setopt histignorespace
|
||||
setopt extended_history
|
||||
setopt share_history
|
||||
setopt hist_verify
|
||||
setopt hist_reduce_blanks
|
||||
|
||||
|
||||
|
||||
# bindkey "$terminfo[kcuu1]" history-substring-search-up
|
||||
# bindkey "$terminfo[kcud1]" history-substring-search-down
|
||||
|
||||
# History search
|
||||
# autoload -Uz up-line-or-beginning-search down-line-or-beginning-search
|
||||
# zle -N up-line-or-beginning-search
|
||||
# zle -N down-line-or-beginning-search
|
||||
# [[ -n "$key[Up]" ]] && bindkey -- "$key[Up]" up-line-or-beginning-search
|
||||
# [[ -n "$key[Down]" ]] && bindkey -- "$key[Down]" down-line-or-beginning-search
|
||||
|
||||
#setopt HIST_IGNORE_SPACE
|
||||
|
||||
# zsh-history-substring-search key bindings
|
||||
@@ -0,0 +1 @@
|
||||
true
|
||||
@@ -0,0 +1,62 @@
|
||||
#{{{ Keybindings
|
||||
# allow ctrl+a and ctrl+e to move to beginning/end of line
|
||||
bindkey '^a' beginning-of-line
|
||||
bindkey '^e' end-of-line
|
||||
# Home, End, Delete keys
|
||||
bindkey "\e[H" beginning-of-line
|
||||
bindkey "\e[F" end-of-line
|
||||
bindkey "\e[3~" delete-char
|
||||
|
||||
# alt+q to push current line and fetch again on next line
|
||||
bindkey '\eq' push-line
|
||||
|
||||
# show man page of current command with alt+h
|
||||
bindkey '\eh' run-help
|
||||
|
||||
# # ctrl+left, ctrl+right to wo to next word
|
||||
# # alt+left, alt+right to wo to next word
|
||||
# bindkey '^[[1;5D' backward-word
|
||||
# bindkey '^[[1;5C' forward-word
|
||||
# bindkey '^[[1;3D' backward-word
|
||||
# bindkey '^[[1;3C' forward-word
|
||||
|
||||
# only slash should be considered as a word separator:
|
||||
slash-backward-kill-word() {
|
||||
local WORDCHARS="${WORDCHARS:s@/@}"
|
||||
# zle backward-word
|
||||
zle backward-kill-word
|
||||
}
|
||||
zle -N slash-backward-kill-word
|
||||
|
||||
# # allow backspace, alt+backspace, ctrl+backspace, ctrl+w for char and word deletion
|
||||
# # These escape sequences are different depending on your terminal
|
||||
# bindkey '^?' backward-delete-char
|
||||
# bindkey '^[[3~' delete-char
|
||||
# bindkey '\e^?' slash-backward-kill-word
|
||||
# bindkey '^H' slash-backward-kill-word
|
||||
bindkey '^w' slash-backward-kill-word
|
||||
|
||||
# Shift-Tab to go back in completion menu
|
||||
zmodload -i zsh/complist # Needed for keybindings in menucomplete mode, and completion styling
|
||||
bindkey -M menuselect '^[[Z' reverse-menu-complete
|
||||
|
||||
# # Gets the nth argument from the last command by pressing Alt+1, Alt+2, ... Alt+5
|
||||
bindkey -s '\e1' "!:0-0 \t"
|
||||
bindkey -s '\e2' "!:1-1 \t"
|
||||
bindkey -s '\e3' "!:2-2 \t"
|
||||
bindkey -s '\e4' "!:3-3 \t"
|
||||
bindkey -s '\e5' "!:4-4 \t"
|
||||
|
||||
# bindkey '^r' history-incremental-search-backward
|
||||
# bindkey '^s' history-incremental-search-forward
|
||||
|
||||
# bindkey '^[[A' history-substring-search-up
|
||||
# bindkey '^[[B' history-substring-search-down
|
||||
#}}}
|
||||
|
||||
# Arrow keys navigation in the edit line
|
||||
bindkey "^[[1;3C" forward-word # Ctrl+Right arrow -> forward one word
|
||||
bindkey "^[[1;3D" backward-word # Ctrl+Left arrow -> backward one word
|
||||
|
||||
bindkey "^?" backward-delete-char # (optional, make Backspace more universal if needed)
|
||||
bindkey "^[[Z" undo # Shift+Tab to undo (from example)
|
||||
@@ -0,0 +1,42 @@
|
||||
#{{{ Options
|
||||
|
||||
# Report time stats of commands running longer than 5 sec
|
||||
REPORTTIME=5
|
||||
|
||||
# in order to use #, ~ and ^ for filename generation grep word
|
||||
# *~(*.gz|*.bz|*.bz2|*.zip|*.Z) -> searches for word not in compressed files
|
||||
# don't forget to quote '^', '~' and '#'!
|
||||
setopt extended_glob
|
||||
|
||||
# display PID when suspending processes as well
|
||||
setopt long_list_jobs
|
||||
|
||||
# report the status of backgrounds jobs immediately
|
||||
setopt notify
|
||||
|
||||
# whenever a command completion is attempted, make sure the entire command path
|
||||
# is hashed first.
|
||||
setopt hash_list_all
|
||||
|
||||
# not just at the end
|
||||
setopt complete_in_word
|
||||
|
||||
# Don't send SIGHUP to background processes when the shell exits.
|
||||
# setopt no_hup
|
||||
|
||||
# * shouldn't match dotfiles. ever.
|
||||
setopt no_glob_dots
|
||||
|
||||
# use zsh style word splitting
|
||||
setopt no_sh_word_split
|
||||
|
||||
# complete_aliases is set in compinit.zsh where it belongs
|
||||
|
||||
# don't error out when unset parameters are used
|
||||
setopt unset
|
||||
|
||||
setopt interactivecomments
|
||||
|
||||
|
||||
setopt ignoreeof
|
||||
#}}}
|
||||
@@ -0,0 +1,2 @@
|
||||
export PATH="$HOME/.config/JetBrains:/usr/local/opt/grep/libexec/gnubin/:$HOME/local/bin:$HOME/local/sbin:$HOME/.local/bin:$HOME/bin:$PATH"
|
||||
echo $PATH | grep -q "$HOME/.dotfiles/bin" || export PATH="$HOME/.dotfiles/bin:$PATH"
|
||||
+205
@@ -0,0 +1,205 @@
|
||||
# ------------------------------------------------------------
|
||||
# Dynamic named directories with cached prefix mapping
|
||||
# Modes (per zshexpn(1)):
|
||||
# n -> resolve dynamic name to path (reply=(path))
|
||||
# d -> resolve path to dynamic name (reply=(name prefixlen))
|
||||
# c -> completion — must call _wanted/compadd directly, return 0/1
|
||||
# ------------------------------------------------------------
|
||||
|
||||
# Debug logging — set DYNDIR_DEBUG=1 to enable
|
||||
typeset -g _ZND_LOG="$HOME/dyndir.log"
|
||||
_znd_log() {
|
||||
(( ${DYNDIR_DEBUG:-0} )) || return 0
|
||||
print -r -- "[$(/bin/date '+%T.%3N')] [$$] $*" >> "$_ZND_LOG"
|
||||
}
|
||||
(( ${DYNDIR_DEBUG:-0} )) && : > "$_ZND_LOG"
|
||||
_znd_log "zdyndir.zsh loaded — DCS_CONTEXT_ROOT=${DCS_CONTEXT_ROOT:-UNSET}"
|
||||
|
||||
# prefix -> base directory (populated lazily so DCS_CONTEXT_ROOT is evaluated
|
||||
# at runtime, not parse time)
|
||||
typeset -gA ZND_PREFIX_BASE=()
|
||||
|
||||
# cache: full dynamic name -> absolute path
|
||||
typeset -gA ZND_NAME_PATH=()
|
||||
|
||||
# ordered prefix list
|
||||
typeset -ga ZND_PREFIXES=(zsh- con- dcs- dev- pan-)
|
||||
|
||||
# cache state
|
||||
typeset -gi ZND_CACHE_READY=0
|
||||
|
||||
_znd_rebuild_cache() {
|
||||
emulate -L zsh
|
||||
setopt extendedglob nullglob
|
||||
|
||||
ZND_PREFIX_BASE=(
|
||||
'zsh-' "${DOTFILES:-$HOME/.dotfiles}"
|
||||
'con-' "$HOME/.config"
|
||||
'dcs-' "${DCS_CONTEXT_ROOT:-}/compose"
|
||||
'dev-' "$HOME/dev"
|
||||
'pan-' "$HOME/PAN_macbook"
|
||||
)
|
||||
|
||||
_znd_log "rebuild_cache: DCS_CONTEXT_ROOT=${DCS_CONTEXT_ROOT:-UNSET} dcs-base=${ZND_PREFIX_BASE[dcs-]}"
|
||||
|
||||
local prefix base dir name
|
||||
ZND_NAME_PATH=()
|
||||
|
||||
for prefix in "${ZND_PREFIXES[@]}"; do
|
||||
base="${ZND_PREFIX_BASE[$prefix]}"
|
||||
if [[ -z "$base" || ! -d "$base" ]]; then
|
||||
_znd_log " skip $prefix => ${base:-EMPTY} (not a dir)"
|
||||
continue
|
||||
fi
|
||||
ZND_NAME_PATH[$prefix]="$base"
|
||||
local count=0
|
||||
for dir in "$base"/*(/N); do
|
||||
ZND_NAME_PATH[${prefix}${dir:t}]="$dir"
|
||||
(( count++ ))
|
||||
done
|
||||
_znd_log " $prefix => $base ($count children)"
|
||||
done
|
||||
|
||||
ZND_CACHE_READY=1
|
||||
_znd_log "rebuild_cache: done — ${#ZND_NAME_PATH} entries"
|
||||
}
|
||||
|
||||
_znd_ensure_cache() { (( ZND_CACHE_READY )) || _znd_rebuild_cache }
|
||||
znd-refresh() { _znd_rebuild_cache }
|
||||
|
||||
|
||||
zsh_directory_name() {
|
||||
emulate -L zsh
|
||||
setopt extendedglob nullglob
|
||||
|
||||
local mode="$1" arg="$2"
|
||||
_znd_log "zsh_directory_name: mode=$mode arg=${arg:-EMPTY}"
|
||||
_znd_ensure_cache
|
||||
|
||||
case "$mode" in
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# n: name -> path
|
||||
# reply=(path), return 0; or return 1
|
||||
# ------------------------------------------------------------------
|
||||
(n)
|
||||
local head="${arg%%/*}" tail=""
|
||||
[[ "$arg" == */* ]] && tail="${arg#"$head"/}"
|
||||
|
||||
local resolved="${ZND_NAME_PATH[$head]}"
|
||||
if [[ -z "$resolved" ]]; then
|
||||
_znd_log " n: NOT FOUND head=$head"
|
||||
return 1
|
||||
fi
|
||||
|
||||
reply=("${resolved}${tail:+/$tail}")
|
||||
_znd_log " n: reply=${reply[1]}"
|
||||
return 0
|
||||
;;
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# d: path -> name
|
||||
# reply=(dynname prefixlen), return 0; or return 1
|
||||
# Used by prompt %~ and directory stack display.
|
||||
# ------------------------------------------------------------------
|
||||
(d)
|
||||
local dir="$arg" prefix base name path
|
||||
for prefix in "${ZND_PREFIXES[@]}"; do
|
||||
base="${ZND_PREFIX_BASE[$prefix]}"
|
||||
[[ -n "$base" && "$dir" == "$base"/* || "$dir" == "$base" ]] || continue
|
||||
# find the most specific (longest) match
|
||||
for name in ${(k)ZND_NAME_PATH}; do
|
||||
path="${ZND_NAME_PATH[$name]}"
|
||||
if [[ "$dir" == "$path"/* || "$dir" == "$path" ]]; then
|
||||
if [[ ${#path} -gt ${#${reply[2]:-}} ]]; then
|
||||
reply=("$name" "${#path}")
|
||||
fi
|
||||
fi
|
||||
done
|
||||
done
|
||||
if [[ -n "${reply[1]}" ]]; then
|
||||
_znd_log " d: reply=${reply[1]} prefixlen=${reply[2]}"
|
||||
return 0
|
||||
fi
|
||||
_znd_log " d: no match for $dir"
|
||||
return 1
|
||||
;;
|
||||
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# c: completion
|
||||
# Must call _wanted/compadd directly — reply is NOT used.
|
||||
# return 0 if candidates added, 1 if none.
|
||||
# Per zshexpn(1) example and _dynamic_directory_name source.
|
||||
# ------------------------------------------------------------------
|
||||
(c)
|
||||
local expl prefix base partial
|
||||
local -a candidates
|
||||
|
||||
# Shift the bracket into the ignored prefix so compadd -S']' produces
|
||||
# ~[name] — the user types ~<TAB> or ~dcs-<TAB>, gets ~[dcs-whoami]
|
||||
# IPREFIX is already '~' (set by _main_complete compset -p 1)
|
||||
IPREFIX="${IPREFIX}["
|
||||
|
||||
# PREFIX is what's typed after the ~ (e.g. "" or "dcs-" or "dcs-who")
|
||||
local typed="${PREFIX}"
|
||||
_znd_log " c: PREFIX=${typed:-EMPTY} IPREFIX=${IPREFIX}"
|
||||
|
||||
# Exact prefix match -> children of that prefix
|
||||
for prefix in "${ZND_PREFIXES[@]}"; do
|
||||
if [[ "$typed" == "$prefix" ]]; then
|
||||
base="${ZND_PREFIX_BASE[$prefix]}"
|
||||
_znd_log " c: exact prefix=$prefix base=$base"
|
||||
[[ -d "$base" ]] || return 1
|
||||
candidates=()
|
||||
local dir
|
||||
for dir in "$base"/*(/N); do
|
||||
candidates+=("${prefix}${dir:t}")
|
||||
done
|
||||
_znd_log " c: exact candidates=${#candidates} first=${candidates[1]:-NONE}"
|
||||
_wanted dynamic-dirs expl 'dynamic directory' \
|
||||
compadd -S ']' -a candidates
|
||||
return
|
||||
fi
|
||||
done
|
||||
|
||||
# Typed starts with a known prefix but has more -> filter children
|
||||
for prefix in "${ZND_PREFIXES[@]}"; do
|
||||
if [[ "$typed" == ${prefix}* ]]; then
|
||||
base="${ZND_PREFIX_BASE[$prefix]}"
|
||||
partial="${typed#$prefix}"
|
||||
_znd_log " c: partial prefix=$prefix partial=$partial base=$base"
|
||||
[[ -d "$base" ]] || return 1
|
||||
candidates=()
|
||||
local dir
|
||||
for dir in "$base"/${~partial}*(/N); do
|
||||
candidates+=("${prefix}${dir:t}")
|
||||
done
|
||||
_znd_log " c: partial candidates=${#candidates} first=${candidates[1]:-NONE}"
|
||||
_wanted dynamic-dirs expl 'dynamic directory' \
|
||||
compadd -S ']' -a candidates
|
||||
return
|
||||
fi
|
||||
done
|
||||
|
||||
# Partial prefix -> offer matching prefixes (no closing ] yet, name incomplete)
|
||||
candidates=()
|
||||
for prefix in "${ZND_PREFIXES[@]}"; do
|
||||
[[ "$prefix" == "$typed"* ]] && candidates+=("$prefix")
|
||||
done
|
||||
_znd_log " c: prefix-list candidates=${#candidates}: ${candidates[@]}"
|
||||
(( ${#candidates} )) || return 1
|
||||
_wanted dynamic-dirs expl 'dynamic directory' \
|
||||
compadd -S '' -a candidates
|
||||
return
|
||||
;;
|
||||
|
||||
(*)
|
||||
_znd_log " unknown mode=$mode"
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
autoload -Uz add-zsh-hook
|
||||
add-zsh-hook precmd _znd_rebuild_cache
|
||||
@@ -0,0 +1,80 @@
|
||||
# zhooks: Display all Zsh hook arrays and functions
|
||||
#
|
||||
# MIT License
|
||||
#
|
||||
# Copyright (c) 2018-2021 Alexandros Kozak
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in all
|
||||
# copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
#
|
||||
# https://github.com/agkozak/zhooks
|
||||
#
|
||||
|
||||
############################################################
|
||||
# Display all Zsh hook arrays and functions
|
||||
#
|
||||
# Returns true if any functions have been associated with
|
||||
# Zsh hooks
|
||||
############################################################
|
||||
zhooks() {
|
||||
|
||||
(( ${+terminfo} )) || zmodload zsh/terminfo
|
||||
if (( ${terminfo[colors]:-0} >= 8 )); then
|
||||
local start_color=${(%):-%F{yellow}}
|
||||
local end_color=${(%):-%f}
|
||||
fi
|
||||
|
||||
local -a hooks
|
||||
hooks=(
|
||||
'chpwd' \
|
||||
'periodic' \
|
||||
'precmd' \
|
||||
'preexec' \
|
||||
'zshaddhistory' \
|
||||
'zsh_directory_name' \
|
||||
'zshexit'
|
||||
)
|
||||
|
||||
local hook hook_array_name hook_array_content hook_function ret
|
||||
for hook in ${hooks[@]}; do
|
||||
# Display contents of hook arrays
|
||||
hook_array_name="${hook}_functions"
|
||||
hook_array_content=$(print -l -- ${${(P)hook_array_name}[@]})
|
||||
if [[ -n $hook_array_content ]]; then
|
||||
printf -- '%s:\n%s\n\n' "${start_color}${hook_array_name}${end_color}" "$hook_array_content"
|
||||
(( ret++ ))
|
||||
fi
|
||||
# Display defined hook functions
|
||||
if (( ${+functions[$hook]} )); then
|
||||
hook_function=$(whence -c $hook)
|
||||
printf -- '%s\n\n' "${start_color}${hook_function%%\(*}${end_color}${hook_function#* }"
|
||||
(( ret++ ))
|
||||
fi
|
||||
done
|
||||
|
||||
(( ret ))
|
||||
}
|
||||
|
||||
############################################################
|
||||
# Unload function
|
||||
#
|
||||
# See https://github.com/agkozak/Zsh-100-Commits-Club/blob/master/Zsh-Plugin-Standard.adoc#unload-fun
|
||||
############################################################
|
||||
zhooks_plugin_unload() {
|
||||
unfunction zhooks $0
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
#!/usr/bin/env zsh
|
||||
# ===============================================================
|
||||
# zshenv — Earliest Initialisation
|
||||
# ===============================================================
|
||||
|
||||
#typeset -rg INIT_PATH=$PATH
|
||||
#typeset -rg INIT_EDITOR=$EDITOR
|
||||
#typeset -rg EDITOR=vi
|
||||
#print "${EDITOR:?no editor} - ${INIT_EDITOR:?no init}"
|
||||
|
||||
typeset -g ZDOTDIR="$HOME/.dotfiles/zsh"
|
||||
typeset -g DOTFILES="$HOME/.dotfiles"
|
||||
|
||||
|
||||
# XDG
|
||||
export XDG_CONFIG_HOME=${XDG_CONFIG_HOME:-$HOME/.config}
|
||||
export XDG_CACHE_HOME=${XDG_CACHE_HOME:-$HOME/.cache}
|
||||
export XDG_DATA_HOME=${XDG_DATA_HOME:-$HOME/.local/share}
|
||||
export XDG_STATE_HOME=${XDG_STATE_HOME:-$HOME/.local/state}
|
||||
export XDG_RUNTIME_DIR=${XDG_RUNTIME_DIR:-$HOME/.xdg}
|
||||
export XDG_PROJECTS_DIR=${XDG_PROJECTS_DIR:-$HOME/PAN_macbook}
|
||||
|
||||
# Fish-like dirs
|
||||
: ${__zsh_config_dir:=${ZDOTDIR:-${XDG_CONFIG_HOME:-$DOTFILES}/zsh}}
|
||||
: ${__zsh_user_data_dir:=${XDG_DATA_HOME:-$HOME/.local/share}/zsh}
|
||||
: ${__zsh_cache_dir:=${XDG_CACHE_HOME:-$HOME/.cache}/zsh}
|
||||
|
||||
# Ensure Zsh directories exist.
|
||||
() {
|
||||
local zdir
|
||||
for zdir in $@; do
|
||||
[[ -d "${(P)zdir}" ]] || mkdir -p -- "${(P)zdir}"
|
||||
done
|
||||
} __zsh_{config,user_data,cache}_dir XDG_{CONFIG,CACHE,DATA,STATE}_HOME XDG_{RUNTIME,PROJECTS}_DIR
|
||||
# export ZSH="/bin/zsh" # removed: conflicts with antidote OMZ path (antidote sets this)
|
||||
# export PATH="$DOTFILES/bin:$PATH"
|
||||
typeset -g outfile="$HOME/zshrc-log.json"
|
||||
export ZSH_CACHE_DIR=${XDG_CACHE_HOME:-$HOME/.cache}
|
||||
|
||||
export LESSHISTFILE=-
|
||||
|
||||
# Load call_file early
|
||||
if [[ ! -f "$DOTFILES/bin/call_file" ]]; then
|
||||
source "$DOTFILES/bin/call_file"
|
||||
fi
|
||||
|
||||
# Standard environment
|
||||
export LANG=en_GB.UTF-8
|
||||
export LC_ALL=en_GB.UTF-8
|
||||
Reference in New Issue
Block a user