dotfiles

dotfiles - ryukamish edition
Log | Files | Refs | README

.zshrc (9293B)


      1 #!/bin/zsh
      2 
      3 # Exports
      4 
      5 export LANG="en_US.UTF-8"
      6 export LC_ALL="en_US.UTF-8"
      7 
      8 export XDG_DOWNLOAD_DIR="${HOME}/downloads"
      9 export XDG_CONFIG_HOME="${HOME}/.config"
     10 export XDG_CACHE_HOME="${HOME}/.cache"
     11 export XDG_DATA_HOME="${HOME}/.local/share"
     12 export XDG_DESKTOP_DIR="${HOME}/desktop"
     13 export XDG_TEMPLATES_DIR="${HOME}/temp"
     14 export XDG_PUBLICSHARE_DIR="${HOME}/public"
     15 export XDG_DOCUMENTS_DIR="${HOME}/documents"
     16 export XDG_MUSIC_DIR="${HOME}/music"
     17 export XDG_PICTURES_DIR="${HOME}/pictures"
     18 export XDG_VIDEOS_DIR="${HOME}/videos"
     19 
     20 export PATH="$PATH:$HOME/.cargo/bin"
     21 export PATH="$PATH:$HOME/go/bin"
     22 export PATH="$PATH:$HOME/.local/bin"
     23 
     24 export EDITOR="nvim"
     25 
     26 export HISTFILE="${HOME}/.zsh_history"
     27 export HISTCONTROL="ignoredups:ignorespace"
     28 export HISTSIZE="100000"
     29 export HISTFILESIZE="200000"
     30 export SAVEHIST="${HISTSIZE}"
     31 
     32 # ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
     33 # ┃ Functions                                               ┃
     34 # ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
     35 
     36 function _have {
     37   prog="${1}"
     38   os="${2}"
     39 
     40   if [ "${os}" != "" ] && [ "${os}" != "${OS}" ]
     41   then 
     42     return 1
     43   fi
     44 
     45   type "${prog}" > /dev/null 
     46   return "$?"
     47 }
     48 
     49 # Set the runtime variable
     50 if _have sway linux
     51 then
     52 	alias sway-launch="dbus-launch --exit-with-session sway"
     53 	if test -z "${XDG_RUNTIME_DIR}"; then
     54 		export XDG_RUNTIME_DIR=/tmp/"${UID}"-runtime-dir
     55 		if ! test -d "${XDG_RUNTIME_DIR}"; then
     56 			mkdir "${XDG_RUNTIME_DIR}"
     57 			chmod 0700 "${XDG_RUNTIME_DIR}"
     58 		fi
     59 	fi
     60 fi
     61 
     62 # === Media ===
     63 function video-to-gif() {
     64   fps="$3"
     65   if [[ "$3" == "" ]];
     66   then 
     67     fps="10"
     68   fi
     69 
     70   ffmpeg \
     71     -i "$1" \
     72     -filter_complex \
     73     $(printf "%s%s%s%s" \
     74       "[0:v]setpts=0.5*PTS,fps=" \
     75       $fps \
     76       ",scale=800:-1:flags=lanczos,split[s0][s1];" \
     77       "[s0]palettegen[p];[s1][p]paletteuse") \
     78     -filter:a 'atempo=1,atempo=1' \
     79     -loop 0 \
     80     "$2"
     81 }
     82 
     83 function cut() {
     84 	start_time="$2"
     85 	end_time="$3"
     86 	input_file="$1"
     87 
     88 	if [[ "$end_time" == "" ]]; then
     89 		ffmpeg -ss "$start_time" \
     90 			-i "$input_file" \
     91 			-c copy "$(date +"%Y%m%d_%H%M ")$input_file" \
     92 			|| printf "Usage: %s <input file> <start> <end>\n" "$0"
     93 	elif [[ "$end_time" != "" ]]; then
     94 		ffmpeg -ss "$start_time" -to "$end_time" \
     95 			-i "$input_file" \
     96 			-c copy "$(date +"%Y%m%d_%H%M ")$input_file" \
     97 			|| printf "Usage: %s <input file> <start> <end>\n" "$0"
     98 	fi
     99 }
    100 
    101 # make an executable file w/ one line
    102 function tx(){
    103 	file="$1"
    104 	[[ "$file" == "" ]] && echo -e "Usage: $0 <file name>\n"
    105 	if [ -f "$file" ]; then
    106 		echo "$file already exists. Making it executable."
    107 		chmod +x "$file"
    108 	else
    109 		touch "$file" && chmod +x "$file"
    110 	fi
    111 }
    112 
    113 # Waydroid
    114 function droid(){
    115 	case "$1" in
    116 		stop)
    117 			waydroid session stop
    118 			;;
    119 		restart)
    120 			if [ pgrep -a waydroid != "" ]; then
    121 				waydroid session stop
    122 				setsid -f waydroid session start
    123 			else
    124 				setsid -f waydroid session start
    125 			fi
    126 			;;
    127 		*)
    128 			printf "Usage: %s {start|stop}\n" "$0"
    129 			exit 1
    130 	esac
    131 }
    132 
    133 # ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
    134 # ┃ ZSH Plugins                         		                ┃
    135 # ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
    136 
    137 
    138 ZSH_CUSTOM="$HOME/.config/zsh/plugins"
    139 
    140 plugins=(
    141   zsh-autosuggestions
    142   zsh-syntax-highlighting
    143 )
    144 
    145 for plugin in $plugins; do
    146   source "$ZSH_CUSTOM/$plugin/${plugin}.zsh"
    147 done
    148 
    149 ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=#999999"
    150 
    151 # ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
    152 # ┃ Completion system (modern menu)		                      ┃
    153 # ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
    154 
    155 autoload -Uz compinit && compinit
    156 zstyle ':completion:*' menu select	# arrow-key menu
    157 zstyle ':completion:*' matcher-list 'm:{a-z}={A-Za-z}'  # case insensitive
    158 zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}" # colored completion
    159 zstyle ':completion:*' rehash true                # auto-refresh completion if new programs installed
    160 
    161 # ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
    162 # ┃ Keybinds		            			                          ┃
    163 # ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
    164 
    165 bindkey '^[[Z' autosuggest-accept   # Shift+Tab accepts suggestion
    166 bindkey '^ ' autosuggest-accept     # Ctrl+Space also accepts
    167 bindkey '^[[A' history-beginning-search-backward  # Up arrow: search history
    168 bindkey '^[[B' history-beginning-search-forward   # Down arrow: search history
    169 
    170 # Common bindings for Alt + Arrow (Meta + Arrow)
    171 bindkey '^[[1;3C' forward-word      # Alt + Right
    172 bindkey '^[[1;3D' backward-word     # Alt + Left
    173 
    174 # cd into a directory with fzf
    175 source <(fzf --zsh)
    176 
    177 bindkey -s '^f' '~/.local/bin/tmux-sessionizer\n'
    178 
    179 # ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
    180 # ┃ Alias		            	    		                          ┃
    181 # ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
    182 
    183 alias ls='ls --color=auto --group-directories-first'
    184 alias ll='ls -lh --color=auto --group-directories-first'
    185 alias la='ls -lah --color=auto --group-directories-first'
    186 alias grep='grep --color=auto'
    187 alias nv='nvim'
    188 alias ..='cd ..'
    189 alias ...='cd ../..'
    190 alias ....='cd ../../..'
    191 
    192 # ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
    193 # ┃ Prompt with git status		            	                ┃
    194 # ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
    195 
    196 # ========================= Single line prompt ======================
    197 
    198 # Load version control info
    199 autoload -Uz vcs_info
    200 
    201 # Load colors
    202 autoload -Uz colors && colors
    203 
    204 # Run vcs_info before each prompt
    205 precmd_functions+=(vcs_info)
    206 
    207 # Enable prompt substitution
    208 setopt prompt_subst
    209 
    210 # Configure the format for git
    211 zstyle ':vcs_info:git:*' formats ' (%b)'
    212 zstyle ':vcs_info:git:*' enable git
    213 
    214 # Set the PROMPT variable to include the vcs_info_msg_0_ variable
    215 PROMPT='%F{#bb9af7}%~%f%F{#7dcfff}${vcs_info_msg_0_}%f %# '
    216 
    217 # ===================== Double line prompt ======================
    218 
    219 # autoload -Uz vcs_info      # loads zsh's version-control info system
    220 # setopt PROMPT_SUBST        # allows variable/command expansion inside PROMPT
    221 
    222 # palette — catppuccin mocha (prominent accents)
    223 # MAUVE='%F{#cba6f7}'        # signature Mocha accent — used for username
    224 # BLUE='%F{#89b4fa}'         # used for current path
    225 # TEAL='%F{#94e2d5}'         # used for git branch name
    226 # YELLOW='%F{#f9e2af}'       # used for unstaged-changes marker
    227 # PEACH='%F{#fab387}'        # used for staged-changes marker
    228 # PINK='%F{#f5c2e7}'         # used for git action (rebase/merge/etc)
    229 # RED='%F{#f38ba8}'          # used for prompt arrow on command failure
    230 # GREEN='%F{#a6e3a1}'        # used for prompt arrow on command success
    231 # SUBTEXT='%F{#a6adc8}'      # muted tone for structural characters/text
    232 # RESET='%f'                 # resets foreground color back to default
    233 
    234 # format for normal git state (branch + unstaged/staged indicators)
    235 # zstyle ':vcs_info:git:*' formats "${SUBTEXT}on ${TEAL}%b${YELLOW}%u${PEACH}%c${RESET}"
    236 # format used during an in-progress git action (e.g. rebase, merge)
    237 # zstyle ':vcs_info:git:*' actionformats "${SUBTEXT}on ${TEAL}%b${SUBTEXT}|${PINK}%a${RESET}"
    238 
    239 # zstyle ':vcs_info:*' check-for-changes true   # enable staged/unstaged detection (can slow big repos)
    240 # zstyle ':vcs_info:*' unstagedstr ' *'         # symbol shown when there are unstaged changes
    241 # zstyle ':vcs_info:*' stagedstr ' +'           # symbol shown when there are staged changes
    242 
    243 # precmd() { vcs_info }      # runs vcs_info before each prompt draw, refreshing git status
    244 
    245 # PROMPT='
    246 # ${SUBTEXT}╭─${MAUVE}%n${SUBTEXT}@%m ${BLUE}%~${RESET} ${vcs_info_msg_0_}
    247 # ${SUBTEXT}╰─%(?.${GREEN}.${RED})❯${RESET} '
    248 # line 1: top border, username (%n), host (%m), current dir (%~), git info
    249 # line 2: bottom border + arrow — %(?.X.Y) is a ternary: X if last command
    250 #         succeeded (exit code 0), Y otherwise
    251 
    252 # Starship prompt
    253 # for times when prompt gets boring
    254 # eval "$(starship init zsh)"