zsh: consistent function naming
This commit is contained in:
parent
a5ee1b137b
commit
bc602776af
3 changed files with 85 additions and 85 deletions
|
@ -21,7 +21,7 @@ prepend_unique() {
|
|||
esac
|
||||
}
|
||||
|
||||
setup_environment() {
|
||||
fs_setup_environment() {
|
||||
export XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}"
|
||||
export XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
|
||||
export XDG_DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}"
|
||||
|
@ -40,7 +40,7 @@ setup_environment() {
|
|||
export PYTHONSTARTUP="$XDG_CONFIG_HOME/python/startup.py"
|
||||
}
|
||||
|
||||
setup_path_and_manpath() {
|
||||
fs_setup_path_and_manpath() {
|
||||
# Prevent path_helper from messing with the PATH when starting tmux.
|
||||
#
|
||||
# Clearing PATH before path_helper executes (from /etc/profile) will prevent it
|
||||
|
@ -78,7 +78,7 @@ setup_path_and_manpath() {
|
|||
|
||||
# Some packages are installed by Homebrew in non-standard locations, in order to
|
||||
# prevent conflicts with their system versions.
|
||||
setup_brew_keg_only_packages() {
|
||||
fs_setup_brew_keg_only_packages() {
|
||||
have brew || return
|
||||
|
||||
local packages=(
|
||||
|
@ -102,7 +102,7 @@ setup_brew_keg_only_packages() {
|
|||
done
|
||||
}
|
||||
|
||||
setup_tools() {
|
||||
fs_setup_tools() {
|
||||
have nvim && EDITOR="nvim"
|
||||
[ -z $EDITOR ] && have vim && EDITOR="vim"
|
||||
[ -z $EDITOR ] && have vi && EDITOR="vi"
|
||||
|
@ -123,7 +123,7 @@ setup_tools() {
|
|||
#
|
||||
# How to configure Windows Firewall for Xserver: https://skeptric.com/wsl2-xserver/
|
||||
# How to check if running in WSL: https://stackoverflow.com/a/61014411
|
||||
setup_wsl_display() {
|
||||
fs_setup_wsl_display() {
|
||||
if [ -n "$(uname -r | sed -n 's/.*\( *Microsoft *\).*/\1/ip')" ] && have xset; then
|
||||
local xdisplay="$(awk '/nameserver/ {print $2; exit}' /etc/resolv.conf 2>/dev/null):0.0"
|
||||
if DISPLAY="$xdisplay" timeout '0.2s' xset q >/dev/null 2>&1; then
|
||||
|
@ -134,16 +134,16 @@ setup_wsl_display() {
|
|||
}
|
||||
|
||||
# Load additional local configuration if present.
|
||||
setup_local_profile() {
|
||||
fs_setup_local_profile() {
|
||||
local profile="$HOME/.local/etc/zsh/zprofile"
|
||||
[ -r "$profile" ] && source "$profile"
|
||||
}
|
||||
|
||||
# zmodload zsh/zprof
|
||||
setup_environment
|
||||
setup_path_and_manpath
|
||||
setup_brew_keg_only_packages
|
||||
setup_tools # NOTE: this must be done _after_ `setup_environment`.
|
||||
setup_wsl_display
|
||||
setup_local_profile
|
||||
fs_setup_environment
|
||||
fs_setup_path_and_manpath
|
||||
fs_setup_brew_keg_only_packages
|
||||
fs_setup_tools # NOTE: this must be done _after_ `fs_setup_environment`.
|
||||
fs_setup_wsl_display
|
||||
fs_setup_local_profile
|
||||
# zprof
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
setup_terminal() {
|
||||
fs_setup_terminal() {
|
||||
# Make ctrl-q and ctrl-s available to terminal applications.
|
||||
stty start undef stop undef
|
||||
}
|
||||
|
||||
setup_aliases() {
|
||||
fs_setup_aliases() {
|
||||
# ls: make `ls` group directories first if supported.
|
||||
# lsc: force `ls` to use color output (e.g. for piping into `less`).
|
||||
|
||||
|
@ -51,7 +51,7 @@ setup_aliases() {
|
|||
}
|
||||
|
||||
# source "$ZDOTDIR/completion.zsh"
|
||||
setup_completion() {
|
||||
fs_setup_completion() {
|
||||
# Enable additional completions from packages in `/usr/local`.
|
||||
local vendor="/usr/local/share/zsh/vendor-completions"
|
||||
[ -d "$vendor" ] && fpath=("$vendor" $fpath)
|
||||
|
@ -128,7 +128,7 @@ setup_completion() {
|
|||
bindkey -M menuselect 'b' vi-backward-word
|
||||
}
|
||||
|
||||
setup_history() {
|
||||
fs_setup_history() {
|
||||
setopt APPEND_HISTORY # Append history rather than overwrite.
|
||||
setopt EXTENDED_HISTORY # Save beginning timestamp and duration.
|
||||
setopt INC_APPEND_HISTORY # Don't wait until shell exits to save history.
|
||||
|
@ -139,14 +139,14 @@ setup_history() {
|
|||
SAVEHIST=1000000
|
||||
}
|
||||
|
||||
setup_zle() {
|
||||
fs_setup_zle() {
|
||||
bindkey -v # Use vi mode for line editing.
|
||||
export KEYTIMEOUT=1 # 10ms delay for <esc> to switch to command mode.
|
||||
|
||||
#############################
|
||||
# ZLE Widgets
|
||||
#############################
|
||||
fs-set-cursor-shape() {
|
||||
fs_set_cursor_shape() {
|
||||
local block='\e[1 q' # blinking block
|
||||
local underline='\e[3 q' # blinking underline, 4 for steady
|
||||
local bar='\e[5 q' # blinkind bar, 6 for steady
|
||||
|
@ -166,27 +166,27 @@ setup_zle() {
|
|||
autoload -Uz add-zle-hook-widget
|
||||
|
||||
# Start new prompts with bar shaped cursor.
|
||||
add-zle-hook-widget line-init fs-zle-line-init
|
||||
fs-zle-line-init() {
|
||||
fs-set-cursor-shape bar
|
||||
add-zle-hook-widget line-init fs_zle_line_init
|
||||
fs_zle_line_init() {
|
||||
fs_set_cursor_shape bar
|
||||
}
|
||||
|
||||
# Switch cursor shape depending on editing mode.
|
||||
add-zle-hook-widget keymap-select fs-zle-keymap-select
|
||||
fs-zle-keymap-select() {
|
||||
add-zle-hook-widget keymap-select fs_zle_keymap_select
|
||||
fs_zle_keymap_select() {
|
||||
case $KEYMAP in
|
||||
vicmd) fs-set-cursor-shape block ;;
|
||||
viins|main) fs-set-cursor-shape bar ;;
|
||||
vicmd) fs_set_cursor_shape block ;;
|
||||
viins|main) fs_set_cursor_shape bar ;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Clear completion menus and other status line text.
|
||||
zle -N fs-zle-clear-status-line
|
||||
fs-zle-clear-status-line() { zle -R -c; }
|
||||
zle -N fs_zle_clear_status_line
|
||||
fs_zle_clear_status_line() { zle -R -c; }
|
||||
|
||||
# Change root directory of the current git repository, if in one.
|
||||
zle -N fs-zle-cd-git-root
|
||||
fs-zle-cd-git-root() {
|
||||
zle -N fs_zle_cd_git_root
|
||||
fs_zle_cd_git_root() {
|
||||
local top_level="$(git rev-parse --show-toplevel 2>/dev/null)"
|
||||
[[ -z "$top_level" ]] && return 1
|
||||
zle push-line
|
||||
|
@ -203,11 +203,11 @@ setup_zle() {
|
|||
# -------------- CTRL -------------------------------
|
||||
bindkey -M viins '^a' vi-beginning-of-line
|
||||
bindkey -M viins '^e' vi-end-of-line
|
||||
bindkey -M viins '^g' fs-zle-cd-git-root
|
||||
bindkey -M viins '^g' fs_zle_cd_git_root
|
||||
bindkey -M viins '^j' history-beginning-search-forward
|
||||
bindkey -M viins '^k' history-beginning-search-backward
|
||||
bindkey -M viins '^l' clear-screen
|
||||
bindkey -M viins '^q' fs-zle-clear-status-line
|
||||
bindkey -M viins '^q' fs_zle_clear_status_line
|
||||
# ^r history search using fzf
|
||||
# ^t paste file/directory using fzf
|
||||
bindkey -M viins '^u' kill-whole-line
|
||||
|
@ -228,7 +228,7 @@ setup_zle() {
|
|||
# fzf
|
||||
#############################
|
||||
if type -p fzf >/dev/null; then
|
||||
setup_zle_fzf
|
||||
fs_setup_zle_fzf
|
||||
else
|
||||
# Fall back to incremental search
|
||||
bindkey -M viins '^r' history-incremental-search-backward
|
||||
|
@ -238,11 +238,11 @@ setup_zle() {
|
|||
fi
|
||||
}
|
||||
|
||||
setup_zle_fzf() {
|
||||
fs_setup_zle_fzf() {
|
||||
local fzf_config="$ZDOTDIR/fzf/key-bindings.zsh"
|
||||
[ -r "$fzf_config" ] || return
|
||||
|
||||
fzf_find() {
|
||||
fs_fzf_find() {
|
||||
local excluded_dirs=("-name '.*'") # Exclude hidden directories.
|
||||
if [ "$(uname -s)" = "Darwin" ] && [ "$(pwd)" = "$HOME" ]; then
|
||||
# These macOS directories would make the find command unusable (too slow).
|
||||
|
@ -271,24 +271,24 @@ setup_zle_fzf() {
|
|||
eval "command find -L . -mindepth 1 $excluded -o $included 2>/dev/null | cut -c3-"
|
||||
}
|
||||
|
||||
fzf_find_files() {
|
||||
fzf_find "-type d" "-type f"
|
||||
fs_fzf_find_files() {
|
||||
fs_fzf_find "-type d" "-type f"
|
||||
}
|
||||
|
||||
fzf_find_dirs() {
|
||||
fzf_find "-type d"
|
||||
fs_fzf_find_dirs() {
|
||||
fs_fzf_find "-type d"
|
||||
}
|
||||
|
||||
source "$fzf_config"
|
||||
export FZF_CTRL_T_COMMAND=fzf_find_files
|
||||
export FZF_ALT_C_COMMAND=fzf_find_dirs
|
||||
export FZF_CTRL_T_COMMAND=fs_fzf_find_files
|
||||
export FZF_ALT_C_COMMAND=fs_fzf_find_dirs
|
||||
export FZF_CTRL_T_OPTS=--border-label='" Select file(s) "'
|
||||
export FZF_CTRL_R_OPTS=--border-label='" History search "'
|
||||
export FZF_ALT_C_OPTS=--border-label='" Change directory "'
|
||||
}
|
||||
|
||||
# Colorful man pages.
|
||||
setup_man_pages() {
|
||||
fs_setup_man_pages() {
|
||||
# Foreground colors
|
||||
typeset -A fg
|
||||
fg[black]='\e[30m'
|
||||
|
@ -356,11 +356,11 @@ setup_man_pages() {
|
|||
export GROFF_NO_SGR=1
|
||||
}
|
||||
|
||||
setup_prompt() {
|
||||
fs_setup_prompt() {
|
||||
source "$ZDOTDIR/prompt.zsh"
|
||||
}
|
||||
|
||||
setup_eza() {
|
||||
fs_setup_eza() {
|
||||
type -p eza >/dev/null || return
|
||||
|
||||
local black=30
|
||||
|
@ -470,7 +470,7 @@ setup_eza() {
|
|||
export EZA_COLORS="${(pj.:.)colors}"
|
||||
}
|
||||
|
||||
setup_fzf() {
|
||||
fs_setup_fzf() {
|
||||
type -p fzf >/dev/null || return
|
||||
|
||||
local colors=(
|
||||
|
@ -514,7 +514,7 @@ setup_fzf() {
|
|||
}
|
||||
|
||||
# Set up autoload for custom functions.
|
||||
setup_functions() {
|
||||
fs_setup_functions() {
|
||||
fpath=("$ZDOTDIR/functions" $fpath)
|
||||
local filepath
|
||||
for filepath in $ZDOTDIR/functions/*; do
|
||||
|
@ -523,27 +523,27 @@ setup_functions() {
|
|||
}
|
||||
|
||||
# Load additional local configuration if present.
|
||||
setup_local_config() {
|
||||
fs_setup_local_config() {
|
||||
local config="$HOME/.local/etc/zsh/zshrc"
|
||||
[ -r "$config" ] && source "$config" || true
|
||||
}
|
||||
|
||||
# Set up zsh for interactive use (options, prompt, aliases, etc.)
|
||||
setup_zsh_interactive() {
|
||||
fs_setup_zsh_interactive() {
|
||||
setopt INTERACTIVE_COMMENTS # Allow comments in interactive use.
|
||||
setup_terminal
|
||||
setup_aliases
|
||||
setup_completion
|
||||
setup_history
|
||||
setup_zle
|
||||
setup_man_pages
|
||||
setup_prompt
|
||||
setup_functions
|
||||
setup_eza
|
||||
setup_fzf
|
||||
setup_local_config
|
||||
fs_setup_terminal
|
||||
fs_setup_aliases
|
||||
fs_setup_completion
|
||||
fs_setup_history
|
||||
fs_setup_zle
|
||||
fs_setup_man_pages
|
||||
fs_setup_prompt
|
||||
fs_setup_functions
|
||||
fs_setup_eza
|
||||
fs_setup_fzf
|
||||
fs_setup_local_config
|
||||
}
|
||||
|
||||
# zmodload zsh/zprof
|
||||
setup_zsh_interactive
|
||||
fs_setup_zsh_interactive
|
||||
# zprof
|
||||
|
|
|
@ -27,16 +27,16 @@ typeset -gA icons=(
|
|||
[clock]=" "
|
||||
)
|
||||
|
||||
fs-prompt-render-full() {
|
||||
fs_prompt_render_full() {
|
||||
local separator="${zfg[faded]} ❯ "
|
||||
local sections=(
|
||||
"$(fs-prompt-exit-code)"
|
||||
"$(fs-prompt-user-and-hostname)"
|
||||
"$(fs-prompt-pwd)"
|
||||
"$(fs-prompt-git)"
|
||||
"$(fs-prompt-virtualenv)"
|
||||
"$(fs-prompt-jobs)"
|
||||
"$(fs-prompt-exec-time)"
|
||||
"$(fs_prompt_exit_code)"
|
||||
"$(fs_prompt_user_and_hostname)"
|
||||
"$(fs_prompt_pwd)"
|
||||
"$(fs_prompt_git)"
|
||||
"$(fs_prompt_virtualenv)"
|
||||
"$(fs_prompt_jobs)"
|
||||
"$(fs_prompt_exec_time)"
|
||||
)
|
||||
echo "\n${(@pj.$separator.)sections:#}${zfg[rst]}"
|
||||
|
||||
|
@ -51,11 +51,11 @@ fs-prompt-render-full() {
|
|||
echo -n "❯ ${zfg[rst]}"
|
||||
}
|
||||
|
||||
fs-prompt-render-compact() {
|
||||
fs_prompt_render_compact() {
|
||||
echo -n "${zfg[magenta]}❯ ${zfg[rst]}"
|
||||
}
|
||||
|
||||
fs-prompt-exit-code() {
|
||||
fs_prompt_exit_code() {
|
||||
((PROMPT_EXIT_CODE == 0)) && return
|
||||
|
||||
if ((PROMPT_EXIT_CODE > 128 && PROMPT_EXIT_CODE < 160)); then
|
||||
|
@ -65,7 +65,7 @@ fs-prompt-exit-code() {
|
|||
fi
|
||||
}
|
||||
|
||||
fs-prompt-user-and-hostname() {
|
||||
fs_prompt_user_and_hostname() {
|
||||
local parts=()
|
||||
|
||||
# username in red if root, yellow if otherwise relevant
|
||||
|
@ -84,11 +84,11 @@ fs-prompt-user-and-hostname() {
|
|||
}
|
||||
}
|
||||
|
||||
fs-prompt-pwd() {
|
||||
fs_prompt_pwd() {
|
||||
print "${zfg[cyan]}${icons[folder]}%~"
|
||||
}
|
||||
|
||||
fs-prompt-git() {
|
||||
fs_prompt_git() {
|
||||
local gitstatus # local swallows git's exit code if not on its own line
|
||||
gitstatus=$(command git status --porcelain -b 2>/dev/null) || return
|
||||
|
||||
|
@ -168,15 +168,15 @@ fs-prompt-git() {
|
|||
print "${(j: :)gitinfo}"
|
||||
}
|
||||
|
||||
fs-prompt-virtualenv() {
|
||||
fs_prompt_virtualenv() {
|
||||
[[ -n "$VIRTUAL_ENV" ]] && print "${zfg[green]}${icons[python]}${VIRTUAL_ENV:t}"
|
||||
}
|
||||
|
||||
fs-prompt-jobs() {
|
||||
fs_prompt_jobs() {
|
||||
(($PROMPT_JOB_COUNT > 0)) && print "${zfg[magenta]}${icons[background]}%j"
|
||||
}
|
||||
|
||||
fs-prompt-exec-time() {
|
||||
fs_prompt_exec_time() {
|
||||
(($PROMPT_EXEC_TIME <= 3)) && return # don't print time if under 3s
|
||||
|
||||
local parts=(
|
||||
|
@ -189,12 +189,12 @@ fs-prompt-exec-time() {
|
|||
}
|
||||
|
||||
# Hook triggered when a command is about to be executed.
|
||||
fs-prompt-preexec() {
|
||||
fs_prompt_preexec() {
|
||||
PROMPT_EXEC_START=$EPOCHSECONDS
|
||||
}
|
||||
|
||||
# Hook triggered right before the prompt is drawn.
|
||||
fs-prompt-precmd() {
|
||||
fs_prompt_precmd() {
|
||||
PROMPT_EXIT_CODE=$? # this needs to be captured before anything else runs
|
||||
|
||||
local stop=$EPOCHSECONDS
|
||||
|
@ -204,16 +204,16 @@ fs-prompt-precmd() {
|
|||
|
||||
local job_count='%j'; PROMPT_JOB_COUNT=${(%)job_count}
|
||||
|
||||
PS1='$(fs-prompt-render-full)'
|
||||
PS1='$(fs_prompt_render_full)'
|
||||
}
|
||||
|
||||
# This hook is only used if transient prompt is enabled.
|
||||
fs-prompt-zle-line-finish() {
|
||||
PS1='$(fs-prompt-render-compact)'
|
||||
fs_prompt_zle_line_finish() {
|
||||
PS1='$(fs_prompt_render_compact)'
|
||||
zle reset-prompt
|
||||
}
|
||||
|
||||
fs-setup-prompt() {
|
||||
fs_setup_prompt() {
|
||||
setopt NO_PROMPT_BANG PROMPT_CR PROMPT_PERCENT PROMPT_SP PROMPT_SUBST
|
||||
export PROMPT_EOL_MARK='' # don't show % when a partial line is preserved
|
||||
export VIRTUAL_ENV_DISABLE_PROMPT=1 # we're doing it ourselves
|
||||
|
@ -221,16 +221,16 @@ fs-setup-prompt() {
|
|||
zmodload zsh/datetime # so that $EPOCHSECONDS is available
|
||||
|
||||
autoload -Uz add-zsh-hook
|
||||
add-zsh-hook preexec fs-prompt-preexec
|
||||
add-zsh-hook precmd fs-prompt-precmd
|
||||
add-zsh-hook preexec fs_prompt_preexec
|
||||
add-zsh-hook precmd fs_prompt_precmd
|
||||
|
||||
# Change to false to disable transient prompt.
|
||||
local use_transient_prompt=true
|
||||
if $use_transient_prompt; then
|
||||
autoload -Uz add-zle-hook-widget
|
||||
add-zle-hook-widget line-finish fs-prompt-zle-line-finish
|
||||
add-zle-hook-widget line-finish fs_prompt_zle_line_finish
|
||||
PS2="${zfg[magenta]}%_❯${zfg[rst]} "
|
||||
fi
|
||||
}
|
||||
|
||||
fs-setup-prompt
|
||||
fs_setup_prompt
|
||||
|
|
Loading…
Add table
Reference in a new issue