diff --git a/.lnk b/.lnk index e3e339d..fd0bd7b 100644 --- a/.lnk +++ b/.lnk @@ -3,3 +3,8 @@ .zsh_plugins.zsh .zshenv .zshrc +.zshrc.d/aliases.zsh +.zshrc.d/colors.zsh +.zshrc.d/environment.zsh +.zshrc.d/functions.zsh +.zshrc.d/options.zsh diff --git a/.zshrc.d/aliases.zsh b/.zshrc.d/aliases.zsh new file mode 100644 index 0000000..0d0df00 --- /dev/null +++ b/.zshrc.d/aliases.zsh @@ -0,0 +1,32 @@ +# vim: set filetype=sh nospell: + +## Use the kitty ssh kitten so that terminfo will be copied over to the remote +## otherwise the remote doesn't recognize kitty terminal +alias ssh="kitten ssh" +alias mosh='mosh --ssh="kitten ssh"' + +# Show process names by default with pgrep +alias pgrep='pgrep -l' + +# Use ov as less +alias less=ov + +alias fd=fdfind + +# Use eza as ls +alias la="eza -a --sort time" +alias ls="eza --sort time" +alias ll="eza -l --sort time" +alias lsd="eza -D" +alias lsf="eza -f" + +alias grep='grep --color=auto' +alias fgrep='fgrep --color=auto' +alias egrep='egrep --color=auto' + +# Add an "alert" alias for long running commands. Use like so: +# sleep 10; alert +alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"' + +## Use main clipbard by default with xclip +alias xclip="xclip -selection clipboard" diff --git a/.zshrc.d/colors.zsh b/.zshrc.d/colors.zsh new file mode 100644 index 0000000..388e08f --- /dev/null +++ b/.zshrc.d/colors.zsh @@ -0,0 +1,18 @@ +COLOR_1='\033[1;34m' # Primary color +COLOR_2='\033[0;96m' # Secondary color +COLOR_LIGHT='\033[2m' + +COLOR_ERROR='\033[1;31m' +COLOR_WARN='\033[0;33m' +COLOR_SUCCESS='\033[0;32m' + +TEXT_RESET='\033[0m' +TEXT_ITAL='\e[3m' +TEXT_ULINE='\e[4m' + +CYAN_B='\033[1;96m' +YELLOW='\033[0;93m' +RED_B='\033[1;31m' +GREEN='\033[0;32m' +PURPLE='\033[0;35m' + diff --git a/.zshrc.d/environment.zsh b/.zshrc.d/environment.zsh new file mode 100644 index 0000000..153941f --- /dev/null +++ b/.zshrc.d/environment.zsh @@ -0,0 +1,41 @@ +# vim: set filetype=sh nospell: + +# Set language. +export LANG=${LANG:-en_US.UTF-8} + +# Reduce key delay +export KEYTIMEOUT=${KEYTIMEOUT:-1} + +# Ensure path arrays do not contain duplicates. +typeset -gU cdpath fpath mailpath path + +### History settings ### +setopt BANG_HIST # Treat the '!' character specially during expansion. +setopt EXTENDED_HISTORY # Write the history file in the ':start:elapsed;command' format. +setopt HIST_EXPIRE_DUPS_FIRST # Expire a duplicate event first when trimming history. +setopt HIST_FIND_NO_DUPS # Do not display a previously found event. +setopt HIST_IGNORE_ALL_DUPS # Delete an old recorded event if a new event is a duplicate. +setopt HIST_IGNORE_DUPS # Do not record an event that was just recorded again. +setopt HIST_IGNORE_SPACE # Do not record an event starting with a space. +setopt HIST_REDUCE_BLANKS # Remove extra blanks from commands added to the history list. +setopt HIST_SAVE_NO_DUPS # Do not write a duplicate event to the history file. +setopt HIST_VERIFY # Do not execute immediately upon history expansion. +setopt INC_APPEND_HISTORY # Write to the history file immediately, not when the shell exits. +setopt NO_HIST_BEEP # Don't beep when accessing non-existent history. +setopt NO_SHARE_HISTORY # Don't share history between all sessions. +setopt HIST_REDUCE_BLANKS # Remove superfluous blanks from each command line being added to the history. + +export HIST_STAMPS="yyyy-mm-dd" +export HISTFILE=~/.zsh_history +export HISTORY_IGNORE="(ls|cd|pwd|exit|fg|hstr)*" +export SAVEHIST=1000 # increase history file size (default is 500) +export HISTSIZE=1000 # increase history size (default is 500) + +export HSTR_CONFIG=prompt-bottom,hicolor,raw-history-view +export HSTR_PROMPT=">" + +# for `zsh-users/zsh-history-substring-search` plugin +HISTORY_SUBSTRING_SEARCH_PREFIXED=1 # Match against the start of each history entry. + +# for `Sam-programs/zsh-calc` plugin +CALC_CMD="qalc -t -c -f <(echo \$BUFFER)" diff --git a/.zshrc.d/functions.zsh b/.zshrc.d/functions.zsh new file mode 100644 index 0000000..b638399 --- /dev/null +++ b/.zshrc.d/functions.zsh @@ -0,0 +1,90 @@ +# vim: set filetype=sh nospell: + +source ~/.zshrc.d/colors.zsh + +## Use bat as cat, except use glow for Markdown files +function cat() { + if [[ $# -eq 1 ]]; then + extension=$([[ "$1" = *.* ]] && echo ".${1##*.}" || echo '') + if [[ "$extension" == ".md" ]]; then + glow --pager -w0 $1 + elif [[ "$extension" == ".html" ]]; then + reader $1 | ov + elif [[ "$extension" == ".json" ]]; then + bat $1 | jq --color-output | bat + else + bat $1 + fi + else + bat $@ + fi +} + +## Use bat to colorize help text +## alias bathelp='bat --plain --language=help' +function help() { + "$@" --help 2>&1 | bat --plain --language=help +} + +## If there is no man page for given command then use help +function man() { + $(whence -p man) $@ + [[ $? -ne 0 ]] && help $1 || true +} + +## Syntax highlighting for apropos +function apropos() { + $(whence -p apropos) "$@" | bat +} + +## Make directory and cd into it +function mcd() { + mkdir $@ + cd $_ +} + +## List dot files +function lsdot() { + eza -d $@ .??* 2>/dev/null +} + +## Wrapper for yazi to provide ability to change current working directory when exiting yazi +function y() { + local tmp="$(mktemp -t "yazi-cwd.XXXXXX")" + yazi "$@" --cwd-file="$tmp" + if cwd="$(cat -- "$tmp")" && [ -n "$cwd" ] && [ "$cwd" != "$PWD" ]; then + builtin cd -- "$cwd" + fi + rm -f -- "$tmp" +} + +function hstr() { + local cmd_file="$(mktemp -t "hist-cmd.XXXXXX")" + 1>&2 2>"$cmd_file" /usr/bin/hstr + + local cmd="$(cat $cmd_file)" + echo "$cmd" >>"$HISTFILE" + echo "$cmd" + eval "$cmd" + rm "$cmd_file" +} + +# set kitty user var `in_editor` when inside sk (skim fuzzy finder) +# need to use whence to find path of executible, functions can be recursive +# so if we don't do this it will just keep calling the sk() function +function sk() { + kitten @ set-user-var in_editor=1 + $(whence -p sk) "$@" + kitten @ set-user-var in_editor +} + +function fzf() { + echo "fzf not installed, using sk (skim)" + sk +} + +function plz() { + last_command=$(fc -l -n -1) + echo "${COLOR_1}Okay, ${COLOR_SUCCESS}${TEXT_ITAL}sudo${TEXT_RESET} ${COLOR_SUCCESS}${last_command}. ${COLOR_1}You're welcome.${TEXT_RESET}" + echo "$last_command" | xargs sudo +} diff --git a/.zshrc.d/options.zsh b/.zshrc.d/options.zsh new file mode 100644 index 0000000..6bf237b --- /dev/null +++ b/.zshrc.d/options.zsh @@ -0,0 +1,19 @@ +# vim: set filetype=sh nospell: + +setopt extended_glob # Use extended globbing syntax (#,~,^). +setopt glob_dots # Don't hide dotfiles from glob patterns. +setopt NO_rm_star_silent # Ask for confirmation for `rm *' or `rm path/*' + +setopt combining_chars # Combine 0-len chars with the base character (eg: accents). +setopt interactive_comments # Enable comments in interactive shell. +setopt rc_quotes # Allow 'Hitchhikers''s Guide' instead of 'Hitchhikers'\''s Guide'. +setopt NO_mail_warning # Don't print a warning message if a mail file has been accessed. +setopt NO_beep # Don't beep on error in line editor. + +# Set Zsh options related to job control. +setopt auto_resume # Attempt to resume existing job before creating a new process. +setopt long_list_jobs # List jobs in the long format by default. +setopt notify # Report status of background jobs immediately. +setopt NO_bg_nice # Don't run all background jobs at a lower priority. +setopt NO_check_jobs # Don't report on jobs when shell exit. +setopt NO_hup # Don't kill jobs on shell exit.