mirror of
https://github.com/ItsDrike/dotfiles.git
synced 2025-06-29 12:10:42 +00:00
Major rewrite: switching back to Arch from NixOS
This commit is contained in:
parent
df585b737b
commit
254181c0fc
121 changed files with 5433 additions and 2371 deletions
|
@ -1 +0,0 @@
|
|||
../shell/profile
|
16
home/.config/zsh/.zprofile
Executable file
16
home/.config/zsh/.zprofile
Executable file
|
@ -0,0 +1,16 @@
|
|||
#!/bin/zsh
|
||||
|
||||
# User .profile definition.
|
||||
# This file is only sourced once, after login, Unlike
|
||||
# .zshrc/.bashrc, which will run whenever a new terminal
|
||||
# is opened.
|
||||
|
||||
# Start graphical session automatically on tty1 if Hyprland or startx is available
|
||||
#if [ "$(tty)" = "/dev/tty1" ] && [ "$UID" != 0 ]; then
|
||||
# if command -v Hyprland >/dev/null; then
|
||||
# ! pidof -s Hyprland >/dev/null 2>&1 && launch-hypr
|
||||
# elif command -v startx >/dev/null; then
|
||||
# ! pidof -s Xorg >/dev/null 2>&1 && exec startx "$XINITRC"
|
||||
# fi
|
||||
#fi
|
||||
|
|
@ -1,138 +1,22 @@
|
|||
#!/usr/bin/zsh
|
||||
|
||||
#########################
|
||||
# History Configuration #
|
||||
#########################
|
||||
export HISTSIZE=12000
|
||||
export SAVEHIST=10000
|
||||
|
||||
# If the internal history needs to be trimmed to add the current command line, setting this
|
||||
# option will cause the oldest history event that has a duplicate to be lost before losing a
|
||||
# unique event from the list. You should be sure to set the value of HISTSIZE to a larger
|
||||
# number than SAVEHIST in order to give you some room for the duplicated events, otherwise
|
||||
# this option will behave just like HIST_IGNORE_ALL_DUPS once the history fills up with unique
|
||||
# events.
|
||||
setopt hist_expire_dups_first
|
||||
|
||||
# When searching for history entries in the line editor, do not display duplicates of a line
|
||||
# previously found, even if the duplicates are not contiguous.
|
||||
setopt hist_find_no_dups
|
||||
|
||||
# If a new command line being added to the history list duplicates an older one, the older
|
||||
# command is removed from the list (even if it is not the previous event).
|
||||
setopt hist_ignore_all_dups
|
||||
|
||||
# Remove command lines from the history list when the first character on the line is a space,
|
||||
# or when one of the expanded aliases contains a leading space. Only normal aliases (not
|
||||
# global or suffix aliases) have this behaviour. Note that the command lingers in the internal
|
||||
# history until the next command is entered before it vanishes, allowing you to briefly reuse
|
||||
# or edit the line. If you want to make it vanish right away without entering another command,
|
||||
# type a space and press return.
|
||||
setopt hist_ignore_space
|
||||
|
||||
# When writing out the history file, older commands that duplicate newer ones are omitted.
|
||||
setopt hist_save_no_dups
|
||||
|
||||
# This option works like APPEND_HISTORY except that new history lines are added to the $HISTFILE
|
||||
# incrementally (as soon as they are entered), rather than waiting until the shell exits.
|
||||
setopt inc_append_history
|
||||
|
||||
# When using history expansion (such as with sudo !!), on enter, first show the expanded command
|
||||
# and only run it after confirmation (another enter press)
|
||||
setopt hist_verify
|
||||
|
||||
###############
|
||||
# ZSH Options #
|
||||
###############
|
||||
|
||||
setopt auto_cd # cd by typing directory name if it's not a command
|
||||
setopt auto_list # automatically list choices on ambiguous completion
|
||||
setopt auto_menu # automatically use menu completion
|
||||
setopt always_to_end # move cursor to end if word had one match
|
||||
setopt interactivecomments # allow comments in interactive mode
|
||||
setopt magicequalsubst # enable filename expansion for arguments of form `x=expression`
|
||||
setopt notify # report the status of background jobs immediately
|
||||
setopt numericglobsort # sort filenames numerically when it makes sense
|
||||
setopt auto_pushd # Make cd act as pushd
|
||||
setopt globdots # Match files starting with . without specifying it (cd <TAB>)
|
||||
#setopt correct_all # autocorrect commands
|
||||
|
||||
##################
|
||||
# Autocompletion #
|
||||
##################
|
||||
|
||||
autoload -Uz compinit
|
||||
zmodload -i zsh/complist # load completion list
|
||||
compinit -d $ZSH_COMPDUMP # Specify compdump file
|
||||
zstyle ':completion:*' menu select # select completions with arrow keys
|
||||
zstyle ':completion:*' group-name '' # group results by category
|
||||
zstyle ':completion:::::' completer _expand _complete _ignored _approximate #enable approximate matches for completion
|
||||
|
||||
#################
|
||||
# Custom config #
|
||||
#################
|
||||
source ~/.config/zsh/rc/fallback_term.zsh
|
||||
source ~/.config/zsh/rc/history.zsh
|
||||
source ~/.config/zsh/rc/opts.zsh
|
||||
source ~/.config/zsh/rc/completion.zsh
|
||||
source ~/.config/zsh/rc/keybinds.zsh
|
||||
source ~/.config/zsh/rc/prompt.zsh
|
||||
source ~/.config/zsh/rc/cmd_not_found.zsh
|
||||
source ~/.config/zsh/rc/auto_cleanup.zsh
|
||||
|
||||
# Setup aliases
|
||||
[ -f ~/.config/shell/aliases ] && source ~/.config/shell/aliases
|
||||
# Load handlers
|
||||
[ -f ~/.config/shell/handlers ] && source ~/.config/shell/handlers
|
||||
# Load key bindings
|
||||
[ -f ~/.config/shell/keybinds ] && source ~/.config/shell/keybinds
|
||||
# Load prompt
|
||||
[ -f ~/.config/shell/prompt ] && source ~/.config/shell/prompt
|
||||
|
||||
#####################
|
||||
# Automatic Cleanup #
|
||||
#####################
|
||||
|
||||
[ -f ~/.zsh-update ] && mv ~/.zsh-update $ZSH_CACHE/.zsh-update
|
||||
[ -f ~/.sudo_as_admin_sucessful ] && rm ~/.sudo_as_admin_successful
|
||||
[ -f ~/.bash_history ] && rm ~/.bash_history
|
||||
|
||||
# Make sure ZSH_CACHE dir exists, avoiding zsh to create it's cache files
|
||||
# in $HOME
|
||||
mkdir -p "$ZSH_CACHE"
|
||||
|
||||
########
|
||||
# Misc #
|
||||
########
|
||||
|
||||
# Color support
|
||||
#autoload -U colors && colors
|
||||
|
||||
# Define TMOUT timeout for TTY and root
|
||||
# [ -z "$DISPLAY" ] && export TMOUT=800
|
||||
# [ $UID -eq 0 ] && export TMOUT=600
|
||||
|
||||
if command -v pyenv >/dev/null 2>&1; then
|
||||
eval "$(pyenv init -)"
|
||||
fi
|
||||
|
||||
if command -v zoxide >/dev/null 2>&1; then
|
||||
eval "$(zoxide init --cmd z zsh)"
|
||||
fi
|
||||
|
||||
#########################
|
||||
# Zgenom Plugin Manager #
|
||||
#########################
|
||||
|
||||
# Load zgenom (plugin manager for ZSH)
|
||||
source "${ZDOTDIR}/.zgenom/zgenom.zsh"
|
||||
|
||||
# Check for zgenom updates
|
||||
# This does not increase startup time
|
||||
zgenom autoupdate
|
||||
|
||||
# If the init script doesn't exist yet
|
||||
if ! zgenom saved; then
|
||||
zgenom load akash329d/zsh-alias-finder
|
||||
zgenom load clarketm/zsh-completions
|
||||
zgenom load zsh-users/zsh-autosuggestions
|
||||
zgenom load zdharma-continuum/fast-syntax-highlighting
|
||||
|
||||
# Generate the init script from plugins above
|
||||
zgenom save
|
||||
fi
|
||||
source ~/.config/zsh/rc/misc.zsh
|
||||
source ~/.config/zsh/rc/plugins.zsh
|
||||
source ~/.config/zsh/rc/zgenom.zsh
|
||||
|
||||
# Override the comment color to make comments visible on black bg
|
||||
# (this needs to be after zgenom, as it requires the zsh-fast-highlighting plugin
|
||||
# to be loaded)
|
||||
FAST_HIGHLIGHT_STYLES[comment]='fg=#696C76'
|
||||
|
|
8
home/.config/zsh/rc/auto_cleanup.zsh
Normal file
8
home/.config/zsh/rc/auto_cleanup.zsh
Normal file
|
@ -0,0 +1,8 @@
|
|||
# This will simply remove some clutter files from the home directory
|
||||
|
||||
[ -f ~/.zsh-update ] && mv ~/.zsh-update $ZSH_CACHE/.zsh-update
|
||||
[ -f ~/.sudo_as_admin_sucessful ] && rm ~/.sudo_as_admin_successful
|
||||
[ -f ~/.bash_history ] && rm ~/.bash_history
|
||||
|
||||
# Make sure ZSH_CACHE dir exists, avoiding zsh to create it's cache files in $HOME
|
||||
mkdir -p "$ZSH_CACHE"
|
39
home/.config/zsh/rc/cmd_not_found.zsh
Normal file
39
home/.config/zsh/rc/cmd_not_found.zsh
Normal file
|
@ -0,0 +1,39 @@
|
|||
if command -v pkgfile > /dev/null; then
|
||||
# Command not found hook that uses `pkgfile` package
|
||||
# to search through the package index in order to find
|
||||
# a package which includes given command, which was resolved
|
||||
# and not found, if there are no such packages, only print
|
||||
# command not found message
|
||||
command_not_found_handler() {
|
||||
cmd="$1"
|
||||
printf 'zsh: command not found: %s' "$cmd" # print command not found asap, then search for packages
|
||||
repos="$(pkgfile "$cmd")"
|
||||
if [ -n "$repos" ]; then
|
||||
printf '\r%s may be found in the following packages:\n' "$cmd"
|
||||
echo "$repos" | while read -r pkg; do
|
||||
printf ' %s\n' "$pkg"
|
||||
done
|
||||
else
|
||||
printf '\n'
|
||||
fi
|
||||
return 127
|
||||
}
|
||||
elif [ -x /usr/lib/command-not-found ] || [ -x /usr/share/command-not-found/command-not-found ]; then
|
||||
# Ubuntu handle for bash default command-not-found
|
||||
# it works similarely to the above arch alternative,
|
||||
# this is based on the original bash implementation
|
||||
command_not_found_handler() {
|
||||
# check because cmd not found could've been removed in the meantime
|
||||
if [ -x /usr/lib/command-not-found ]; then
|
||||
/usr/lib/command-not-found -- "$1"
|
||||
return $?
|
||||
elif [ -x /usr/share/command-not-found/command-not-found ]; then
|
||||
/usr/share/command-not-found/command-not-found -- "$1"
|
||||
return $?
|
||||
else
|
||||
printf "%s: command not found\n" "$1" >&2
|
||||
return 127
|
||||
fi
|
||||
}
|
||||
fi
|
||||
|
19
home/.config/zsh/rc/completion.zsh
Normal file
19
home/.config/zsh/rc/completion.zsh
Normal file
|
@ -0,0 +1,19 @@
|
|||
# Autocompletion behavior of ZSH
|
||||
|
||||
autoload -Uz compinit
|
||||
zmodload -i zsh/complist # load completion list
|
||||
|
||||
if [[ -n "$(print ${ZDOTDIR:-$HOME}/.zcompdump(Nmh+5))" ]]; then
|
||||
# Re-check for new completions, re-creating .zcompdump if necessary.
|
||||
# This check can be quite slow and it's rare that we actually have new completions to load.
|
||||
# For that reason, we only do this if the compdump file is older than 5 hours.
|
||||
compinit
|
||||
else
|
||||
# This will omit the check for new completions,
|
||||
# only re-creating .zcompdump if it doesn't yet exist.
|
||||
compinit -C
|
||||
fi
|
||||
|
||||
zstyle ':completion:*' menu select # select completions with arrow keys
|
||||
zstyle ':completion:*' group-name '' # group results by category
|
||||
zstyle ':completion:::::' completer _expand _complete _ignored _approximate # enable approximate matches for completion
|
8
home/.config/zsh/rc/fallback_term.zsh
Normal file
8
home/.config/zsh/rc/fallback_term.zsh
Normal file
|
@ -0,0 +1,8 @@
|
|||
# If the set $TERM variable doesn't match any configured terminfo entries
|
||||
# fall back to xterm. This fixes SSH connections from unknown terminals
|
||||
|
||||
if ! infocmp "$TERM" &>/dev/null; then
|
||||
echo "Setting \$TERM to xterm-256color due to missing terminfo entry for $TERM."
|
||||
export TERM=xterm-256color
|
||||
fi
|
||||
|
59
home/.config/zsh/rc/history.zsh
Normal file
59
home/.config/zsh/rc/history.zsh
Normal file
|
@ -0,0 +1,59 @@
|
|||
export HISTSIZE=12000
|
||||
export SAVEHIST=10000
|
||||
|
||||
# Append history list to history file once the session exits, rather than replacing
|
||||
# the history file, erasing any past entries
|
||||
setopt APPEND_HISTORY
|
||||
|
||||
# If the internal history needs to be trimmed to add the current command line, setting this
|
||||
# option will cause the oldest history event that has a duplicate to be lost before losing a
|
||||
# unique event from the list. You should be sure to set the value of HISTSIZE to a larger
|
||||
# number than SAVEHIST in order to give you some room for the duplicated events, otherwise
|
||||
# this option will behave just like HIST_IGNORE_ALL_DUPS once the history fills up with unique
|
||||
# events.
|
||||
setopt HIST_EXPIRE_DUPS_FIRST
|
||||
|
||||
# When searching for history entries in the line editor, do not display duplicates of a line
|
||||
# previously found, even if the duplicates are not contiguous.
|
||||
setopt HIST_FIND_NO_DUPS
|
||||
|
||||
# If a new command line being added to the history list duplicates an older one, the older
|
||||
# command is removed from the list (even if it is not the previous event).
|
||||
setopt HIST_IGNORE_ALL_DUPS
|
||||
|
||||
# Remove command lines from the history list when the first character on the line is a space,
|
||||
# or when one of the expanded aliases contains a leading space. Only normal aliases (not
|
||||
# global or suffix aliases) have this behaviour. Note that the command lingers in the internal
|
||||
# history until the next command is entered before it vanishes, allowing you to briefly reuse
|
||||
# or edit the line. If you want to make it vanish right away without entering another command,
|
||||
# type a space and press return.
|
||||
setopt HIST_IGNORE_SPACE
|
||||
|
||||
# When writing out the history file, older commands that duplicate newer ones are omitted.
|
||||
setopt HIST_SAVE_NO_DUPS
|
||||
|
||||
# This option works like APPEND_HISTORY except that new history lines are added to the $HISTFILE
|
||||
# incrementally (as soon as they are entered), rather than waiting until the shell exits.
|
||||
setopt INC_APPEND_HISTORY
|
||||
|
||||
# When using history expansion (such as with sudo !!), on enter, first show the expanded command
|
||||
# and only run it after confirmation (another enter press)
|
||||
setopt HIST_VERIFY
|
||||
|
||||
# Remove superfluous blanks from each command line being added to the history list
|
||||
setopt HIST_REDUCE_BLANKS
|
||||
|
||||
# When writing out the history file, by default zsh uses ad-hoc file locking to avoid known
|
||||
# problems with locking on some operating systems. With this option, locking is done by means
|
||||
# of the `fcntl` system call, where this method is available. This can improve performance on
|
||||
# recent operating systems, and is better at avoiding history corruption when files are stored
|
||||
# on NFS.
|
||||
setopt HIST_FCNTL_LOCK
|
||||
|
||||
# Save each command's beginning time (unix timestamp) and the duration (in seconds) to the
|
||||
# history file.
|
||||
setopt EXTENDED_HISTORY
|
||||
|
||||
# beep in ZLE when a widget attempts to access a history entry which isn’t there
|
||||
unsetopt HIST_BEEP
|
||||
|
65
home/.config/zsh/rc/keybinds.zsh
Normal file
65
home/.config/zsh/rc/keybinds.zsh
Normal file
|
@ -0,0 +1,65 @@
|
|||
# shellcheck disable=SC2030,SC2031,SC2015
|
||||
# Set default keybindings (mostly from oh-my-zsh)
|
||||
|
||||
# Make sure that the terminal is in application mode when zle is active, since
|
||||
# only then values from $terminfo are valid
|
||||
if (( ${+terminfo[smkx]} )) && (( ${+terminfo[rmkx]} )); then
|
||||
function zle-line-init() {
|
||||
echoti smkx
|
||||
}
|
||||
function zle-line-finish() {
|
||||
echoti rmkx
|
||||
}
|
||||
zle -N zle-line-init
|
||||
zle -N zle-line-finish
|
||||
fi
|
||||
|
||||
# Use emacs keybindings
|
||||
bindkey -e
|
||||
|
||||
# Start typing + [Up-Arrow] - fuzzy find history forward
|
||||
if [ -n "${terminfo[kcuu1]}" ]; then
|
||||
autoload -U up-line-or-beginning-search
|
||||
zle -N up-line-or-beginning-search
|
||||
bindkey "${terminfo[kcuu1]}" up-line-or-beginning-search
|
||||
fi
|
||||
# Start typing + [Down-Arrow] - fuzzy find history backward
|
||||
if [ -n "${terminfo[kcud1]}" ]; then
|
||||
autoload -U down-line-or-beginning-search
|
||||
zle -N down-line-or-beginning-search
|
||||
bindkey "${terminfo[kcud1]}" down-line-or-beginning-search
|
||||
fi
|
||||
|
||||
# [Home] - Go to beginning of line
|
||||
[ -n "${terminfo[khome]}" ] && bindkey "${terminfo[khome]}" beginning-of-line || bindkey "^[[H" beginning-of-line
|
||||
# [End] - Go to end of line
|
||||
[ -n "${terminfo[kend]}" ] && bindkey "${terminfo[kend]}" end-of-line || bindkey "^[[F" end-of-line
|
||||
|
||||
# [Shift-Tab] - move through the completion menu backwards
|
||||
[ -n "${terminfo[kcbt]}" ] && bindkey "${terminfo[kcbt]}" reverse-menu-complete
|
||||
|
||||
# [Backspace] - delete backward
|
||||
bindkey '^?' backward-delete-char
|
||||
# [Delete] - delete forward
|
||||
[ -n "${terminfo[kdch1]}" ] && bindkey "${terminfo[kdch1]}" delete-char || bindkey "^[[3~" delete-char
|
||||
# [Ctrl-Delete] - delete whole forward-word
|
||||
bindkey '^[[3;5~' kill-word
|
||||
|
||||
# [Ctrl-RightArrow] - move forward one word
|
||||
bindkey '^[[1;5C' forward-word
|
||||
# [Ctrl-LeftArrow] - move backward one word
|
||||
bindkey '^[[1;5D' backward-word
|
||||
|
||||
# [Ctrl-r] - Search backward incrementally for a specified string. The string may begin with ^ to anchor the search to the beginning of the line.
|
||||
bindkey '^r' history-incremental-search-backward
|
||||
# [PageUp] - Up a line of history
|
||||
[ -n "${terminfo[kpp]}" ] && bindkey "${terminfo[kpp]}" up-line-or-history
|
||||
# [PageDown] - Down a line of history
|
||||
[ -n "${terminfo[knp]}" ] && bindkey "${terminfo[knp]}" down-line-or-history
|
||||
|
||||
# [Space] - do history expansion on space
|
||||
bindkey ' ' magic-space
|
||||
|
||||
# [ctrl+space] Accept suggestion from zsh-autosuggestions plugin
|
||||
bindkey '^ ' autosuggest-accept
|
||||
|
15
home/.config/zsh/rc/misc.zsh
Normal file
15
home/.config/zsh/rc/misc.zsh
Normal file
|
@ -0,0 +1,15 @@
|
|||
# This file contains miscellaneous configurations,
|
||||
# usually required by external applications that isn't suited for plugins.zsh
|
||||
# or just general ZSH/shell settings that don't fit anywhere else
|
||||
|
||||
# Foot terminal uses this sequence to identify a command execution
|
||||
# that way it's possible to use ctrl+shift+z/x to jump between commands
|
||||
if [ "$TERM" = "foot" ]; then
|
||||
precmd() {
|
||||
print -Pn "\e]133;A\e\\"
|
||||
}
|
||||
fi
|
||||
|
||||
# Define TMOUT timeout for TTY and root
|
||||
# [ -z "$DISPLAY" ] && export TMOUT=800
|
||||
# [ $UID -eq 0 ] && export TMOUT=600
|
31
home/.config/zsh/rc/opts.zsh
Normal file
31
home/.config/zsh/rc/opts.zsh
Normal file
|
@ -0,0 +1,31 @@
|
|||
# Set or unset various zsh options.
|
||||
# You can read more about what options are available and what these do in
|
||||
# the ZSH manual: <https://zsh.sourceforge.io/Doc/Release/Options.html>
|
||||
#
|
||||
# Note that history-related options are set from history.zsh, not from here.
|
||||
|
||||
#########################
|
||||
# General/Other options #
|
||||
#########################
|
||||
|
||||
setopt AUTO_CD # cd by typing directory name if it's not a command
|
||||
setopt AUTO_LIST # automatically list choices on ambiguous completion
|
||||
setopt AUTO_MENU # automatically use menu completion
|
||||
setopt MENU_COMPLETE # insert first match immediately on ambiguous completion
|
||||
setopt AUTO_PARAM_SLASH # if a parameter is completed with a directory, add trailing slash instead of space
|
||||
setopt ALWAYS_TO_END # move cursor to end if word had one match
|
||||
setopt INTERACTIVE_COMMENTS # allow comments in interactive mode
|
||||
setopt MAGIC_EQUAL_SUBST # enable filename expansion for arguments of form `x=expression`
|
||||
setopt NOTIFY # report the status of background jobs immediately
|
||||
setopt NUMERIC_GLOB_SORT # sort filenames numerically when it makes sense
|
||||
setopt GLOB_DOTS # Match files starting with . without specifying it (cd <TAB>)
|
||||
|
||||
|
||||
######################
|
||||
# Auto pushd options #
|
||||
######################
|
||||
|
||||
setopt AUTO_PUSHD # Make cd push the old directory onto the directory stack
|
||||
setopt PUSHD_IGNORE_DUPS # don't push multiple copies of the same directory
|
||||
setopt PUSHD_TO_HOME # have pushd with no arguments act like `pushd $HOME`
|
||||
setopt PUSHD_SILENT # do not print the directory stack
|
15
home/.config/zsh/rc/plugins.zsh
Normal file
15
home/.config/zsh/rc/plugins.zsh
Normal file
|
@ -0,0 +1,15 @@
|
|||
# This file loads custom ZSH plugins or runs shell configurations
|
||||
# exposed by various plugins. This often includes custom autocompletions,
|
||||
# but also whatever other functionalities that these may contain.
|
||||
|
||||
if command -v pyenv >/dev/null 2>&1; then
|
||||
eval "$(pyenv init -)"
|
||||
fi
|
||||
|
||||
if command -v zoxide >/dev/null 2>&1; then
|
||||
eval "$(zoxide init zsh --cmd z)"
|
||||
fi
|
||||
|
||||
if command -v eww >/dev/null 2>&1; then
|
||||
eval "$(eww shell-completions --shell zsh)"
|
||||
fi
|
188
home/.config/zsh/rc/prompt.zsh
Executable file
188
home/.config/zsh/rc/prompt.zsh
Executable file
|
@ -0,0 +1,188 @@
|
|||
#!/usr/bin/env zsh
|
||||
# shellcheck disable=SC2155
|
||||
|
||||
# Configuration variables:
|
||||
|
||||
# Once we are too deep in the filestructure, we can usually afford to shorten
|
||||
# the whole working directory and only print something like ~/.../dir3/dir4/dir5
|
||||
# instead of ~/dir1/dir2/dir3/dir4/dir5. If this isn't desired, set this to 0
|
||||
USE_SHORTENED_WORKDIR=1
|
||||
|
||||
# Show how much time it took to run a command
|
||||
CMD_TIME_SHOW=1
|
||||
# Minimum units to show the time precision, if
|
||||
# we use "s" (seconds), and the output took 0s,
|
||||
# we don't print the output at all to avoid clutter.
|
||||
# Same goes for any other units, however with "ms"
|
||||
# (miliseconds), this is very unlikely
|
||||
# Valid options: ms/s/m/h/d
|
||||
CMD_TIME_PRECISION="s"
|
||||
# Minimum time in miliseconds, to print the time took,
|
||||
# if the command takes less than this amount of miliseconds,
|
||||
# don't bother printing the time took, this is nice if you
|
||||
# don't need to see how long commands like 'echo' took
|
||||
# Setting this to 0 will always print the time taken
|
||||
CMD_TIME_MINIMUM=100
|
||||
|
||||
# hide EOL sign ('%')
|
||||
export PROMPT_EOL_MARK=""
|
||||
|
||||
# TTY (pure linux) terminal only has 8-bit color support
|
||||
# (unless you change it in kernel), respect this and downgrade
|
||||
# the color scheme accordingly (it won't look best, but it's
|
||||
# still better than no colors)
|
||||
if [ "$TERM" = "linux" ]; then
|
||||
GREEN="%F{002}"
|
||||
RED="%F{001}"
|
||||
ORANGE="%F{003}"
|
||||
BLUE="%F{004}"
|
||||
LBLUE="%F{006}"
|
||||
PURPLE="%F{005}"
|
||||
else
|
||||
GREEN="%F{047}"
|
||||
RED="%F{196}"
|
||||
ORANGE="%F{214}"
|
||||
BLUE="%F{027}"
|
||||
LBLUE="%F{075}"
|
||||
PURPLE="%F{105}"
|
||||
fi
|
||||
RESET="%f"
|
||||
|
||||
# Signals git status of CWD repository (if any)
|
||||
git_prompt() {
|
||||
ref=$(command git symbolic-ref HEAD 2> /dev/null) || ref=$(command git rev-parse --short HEAD 2> /dev/null) || return 0
|
||||
echo -n " $ORANGE${ref#refs/heads/}"
|
||||
|
||||
if [ -n "$(git status --short 2>/dev/null)" ]; then
|
||||
echo "$RED+"
|
||||
fi
|
||||
}
|
||||
|
||||
# Adds @chroot or @ssh
|
||||
foreign_prompt() {
|
||||
if [ "$(awk '$5=="/" {print $1}' </proc/1/mountinfo)" != "$(awk '$5=="/" {print $1}' </proc/$$/mountinfo)" ]; then
|
||||
echo -n "@${ORANGE}chroot"
|
||||
elif [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
|
||||
echo -n "@${ORANGE}ssh"
|
||||
fi
|
||||
}
|
||||
|
||||
#nd Prints appropriate working directory
|
||||
working_directory() {
|
||||
# By default up to 5 directories will be tolerated before shortening
|
||||
# After we surpass that, first directory (or ~) will be printed together with last 3
|
||||
# This feature uses special symbol '…', but this isn't aviable when in TTY. Because
|
||||
# of this, when we are in TTY, we fall back to longer '...'
|
||||
|
||||
if [ $USE_SHORTENED_WORKDIR != 1 ]; then
|
||||
echo -n " $BLUE$~"
|
||||
elif [ "$TERM" = "linux" ]; then
|
||||
echo -n " $BLUE%(5~|%-1~/.../%3~|%4~)"
|
||||
else
|
||||
echo -n " $BLUE%(5~|%-1~/…/%3~|%4~)"
|
||||
fi
|
||||
}
|
||||
|
||||
# Execution time tracking hooks, this is unique to zsh, as it can add
|
||||
# preexec and precmd hooks. We can utilize this to keep track of the
|
||||
# amount of time it took to run certain command. We store the start time
|
||||
# within a variable: PROMPT_EXEC_TIME_START, which we then compare and
|
||||
# unset after the command was finished. In here, we simply set the
|
||||
# PROMPT_EXEC_TIME_DURATION, which is then used in the actual prompt
|
||||
# This will only be enabled if SHOW_CMD_TIME is 1.
|
||||
exec_time_preexec_hook() {
|
||||
[[ $SHOW_CMD_TIME == 0 ]] && return
|
||||
PROMPT_EXEC_TIME_START=$(date +%s.%N)
|
||||
}
|
||||
exec_time_precmd_hook() {
|
||||
[[ $SHOW_CMD_TIME == 0 ]] && return
|
||||
[[ -z $PROMPT_EXEC_TIME_START ]] && return
|
||||
local PROMPT_EXEC_TIME_STOP="$(date +%s.%N)"
|
||||
PROMPT_EXEC_TIME_DURATION=$(echo "($PROMPT_EXEC_TIME_STOP - $PROMPT_EXEC_TIME_START) * 1000" | bc -l)
|
||||
unset PROMPT_EXEC_TIME_START
|
||||
}
|
||||
format_time() {
|
||||
# Do some formatting to get nice time (e.g. 2m 12s) from miliseconds
|
||||
# $1 is the milisecond amount (int or float)
|
||||
# $2 is the precision (ms/s/m/h/d)
|
||||
local T="$1"
|
||||
local D="$(echo "scale=0;$T/1000/60/60/24" | bc -l)"
|
||||
local H="$(echo "scale=0;$T/1000/60/60%24" | bc -l)"
|
||||
local M="$(echo "scale=0;$T/1000/60%60" | bc -l)"
|
||||
local S="$(echo "scale=0;$T/1000%60" | bc -l)"
|
||||
local MS="$(echo "scale=0;$T%1000" | bc -l)"
|
||||
|
||||
local precision=$2
|
||||
local out=""
|
||||
case "$precision" in
|
||||
"ms") [[ "$MS" -gt 0 ]] && out="$(printf "%dms" "$MS") ${out}"; precision="s" ;&
|
||||
"s") [[ "$S" -gt 0 ]] && out="$(printf "%ds" "$S") ${out}"; precision="m" ;&
|
||||
"m") [[ "$M" -gt 0 ]] && out="$(printf "%dm" "$M") ${out}"; precision="h" ;&
|
||||
"h") [[ "$H" -gt 0 ]] && out="$(printf "%dh" "$H") ${out}"; precision="d" ;&
|
||||
"d") [[ "$D" -gt 0 ]] && out="$(printf "%dd" "$D") ${out}" ;;
|
||||
*) out="$T" ;; # Return $1 ($T) if precision wasn't specified/valid
|
||||
esac
|
||||
printf "%s" "$out"
|
||||
}
|
||||
display_cmd_time() {
|
||||
[[ $CMD_TIME_SHOW == 0 ]] && return
|
||||
[[ -z $PROMPT_EXEC_TIME_DURATION ]] && return
|
||||
# If the time duration is less than minimum time,
|
||||
# don't print the time taken
|
||||
[[ $PROMPT_EXEC_TIME_DURATION -lt $CMD_TIME_MINIMUM ]] && return
|
||||
local time_took="$(format_time "$PROMPT_EXEC_TIME_DURATION" "$CMD_TIME_PRECISION")"
|
||||
# Don't display if the time didn't give us output
|
||||
# this happens when all fields (seconds/minutes/...) are 0,
|
||||
# if we use milisecond precision, this will likely never happen
|
||||
# but with other precisions, it could
|
||||
[ ${#time_took} -eq 0 ] && return
|
||||
echo -n " ${LBLUE}took ${time_took}"
|
||||
}
|
||||
|
||||
setopt promptsubst # enable command substitution in prompt
|
||||
|
||||
# Setup ZSH hooks to display the running time of commands
|
||||
autoload -Uz add-zsh-hook
|
||||
add-zsh-hook preexec exec_time_preexec_hook
|
||||
add-zsh-hook precmd exec_time_precmd_hook
|
||||
|
||||
# Primary Prompt
|
||||
[ "$EUID" -eq 0 ] && PS1="$RED%n$RESET" || PS1="$GREEN%n$RESET" # user
|
||||
PS1+="$(foreign_prompt)"
|
||||
PS1+="$(working_directory)"
|
||||
PS1+="\$(git_prompt)"
|
||||
PS1+="\$(display_cmd_time)"
|
||||
PS1+=" $PURPLE%(!.#.$)$RESET " # Final symbol (# or $)
|
||||
|
||||
# Next line prompt
|
||||
PS2="$RED\ $RESET"
|
||||
|
||||
# Right side prompt
|
||||
RPS1=""
|
||||
if [ "$TERM" = "linux" ]; then
|
||||
# Displaying cmd time here works, but often causes issues when we
|
||||
# resize the terminal, since right prompts can be annoying to deal
|
||||
# with when resizing. This would run relatively often so it makes
|
||||
# more sense to only use it in PS1 (left prompt), but if desired,
|
||||
# this can be uncommented
|
||||
#RPS1+="\$(display_cmd_time)"
|
||||
|
||||
# If we find a non-zero return code, print it in the right prompt,
|
||||
# use X here, to avoid issues with TTY not having support for
|
||||
# a nicer unicode character that we use otherwise ("↵")
|
||||
RPS1+="%(?..${RED}%? X$RESET)"
|
||||
else
|
||||
# Read comments for the section above.
|
||||
#RPS1+="\$(display_cmd_time)"
|
||||
|
||||
# NOTE: "↵" symbol could cause issues with on some terminals/machines that
|
||||
# don't handle unicode well, this issue could be very confusing to debug,
|
||||
# and it would not be apparent what's wrong since the symbol itself will
|
||||
# be drawn, however when it is drawn, it will also move the cursor line
|
||||
# 2 places back since this symbol is made up of 3 bytes (in unicode) and
|
||||
# regular ASCII characters only take up 1 byte, this means that whenever
|
||||
# the right-side prompt appears (on error), the prompt would have this issue.
|
||||
RPS1="%(?..${RED}%? ↵$RESET)"
|
||||
fi
|
||||
|
||||
|
18
home/.config/zsh/rc/zgenom.zsh
Normal file
18
home/.config/zsh/rc/zgenom.zsh
Normal file
|
@ -0,0 +1,18 @@
|
|||
# Load zgenom (plugin manager for ZSH)
|
||||
source "${ZDOTDIR}/.zgenom/zgenom.zsh"
|
||||
|
||||
# Check for zgenom updates
|
||||
# This does not increase startup time
|
||||
zgenom autoupdate
|
||||
|
||||
# If the init script doesn't exist yet
|
||||
if ! zgenom saved; then
|
||||
zgenom load akash329d/zsh-alias-finder
|
||||
zgenom load clarketm/zsh-completions
|
||||
zgenom load zsh-users/zsh-autosuggestions
|
||||
zgenom load zdharma-continuum/fast-syntax-highlighting
|
||||
|
||||
# Generate the init script from plugins above
|
||||
zgenom save
|
||||
fi
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue