···
zplug "plugins/systemd", from:oh-my-zsh
35
-
# Load file from ~/.zshrc.d
36
-
zplug "${HOME}/.zshrc.d", from:local, use:'*'
export SHELL=/usr/bin/zsh
···
# Automatically remove duplicates from these arrays
typeset -gU path cdpath manpath fpath
115
+
##############################################################################
117
+
##############################################################################
119
+
if [ -e "/etc/debian_version" ]; then
120
+
alias acs='sudo apt-cache search'
121
+
alias acp='sudo apt-cache policy'
122
+
alias agu='sudo apt update'
123
+
alias agud='sudo apt update && sudo apt dist-upgrade'
124
+
alias agi='sudo apt install'
125
+
alias afs='sudo apt-file search'
126
+
alias afu='sudo apt-file update'
127
+
alias aac='sudo apt autoclean'
128
+
alias agc='sudo apt clean'
129
+
alias agli='sudo apt list --installed'
130
+
alias agp='sudo apt purge'
131
+
alias agr='sudo apt remove'
132
+
alias agar='sudo apt autoremove'
136
+
if [ -e "/etc/redhat-release" ]; then
137
+
alias dnfc='sudo dnf clean all'
138
+
alias dnfgi='sudo dnf groupinstall'
139
+
alias dnfgl='dnf grouplist'
140
+
alias dnfgr='sudo dnf groupremove'
141
+
alias dnfi='sudo dnf install'
142
+
alias dnfl='dnf list'
143
+
alias dnfli='dnf list installed'
144
+
alias dnfmc='dnf makecache'
145
+
alias dnfp='dnf info'
146
+
alias dnfr='sudo dnf remove'
147
+
alias dnfs='dnf search'
148
+
alias dnfu='sudo dnf update'
152
+
if test -f /bin/lsd; then
156
+
alias lal='lsd -al'
158
+
alias ls='ls --color=auto'
165
+
alias grep='grep --color'
167
+
# Prompt user before overwriting files
172
+
# Display zsh functions with bat
173
+
alias zfun='functions | bat -l zsh'
176
+
if command -v bat >/dev/null; then
181
+
# Assorted global aliases
182
+
alias -g H='| head'
183
+
alias -g T='| tail'
184
+
alias -g G='| grep'
185
+
alias -g L='| less -FRX'
186
+
alias -g CC='| xclip -selection clipboard'
188
+
# Get public IP address
189
+
alias pubip4='curl -s -m 5 ipv4.icanhazip.com'
190
+
alias pubip6='curl -s -m 5 ipv6.icanhazip.com'
193
+
if test -x "$(command -v firewall-cmd)"; then
194
+
alias fw='sudo firewall-cmd'
195
+
alias fwp='sudo firewall-cmd --permanent'
196
+
alias fwr='sudo firewall-cmd --reload'
197
+
alias fwrp='sudo firewall-cmd --runtime-to-permanent'
202
+
alias gcl='git clone'
203
+
alias gcmsg='git commit -m'
204
+
alias gd='git diff'
205
+
alias gl='git pull'
206
+
alias gp='git push'
207
+
alias gr='git remote'
208
+
alias grbi='git rebase -i'
210
+
alias grv='git remote -v'
211
+
alias gst='git status'
214
+
##############################################################################
216
+
##############################################################################
219
+
key[Home]="${terminfo[khome]}"
220
+
key[End]="${terminfo[kend]}"
222
+
[[ -n "${key[Home]}" ]] && bindkey -- "${key[Home]}" beginning-of-line
223
+
[[ -n "${key[End]}" ]] && bindkey -- "${key[End]}" end-of-line
225
+
if (( ${+terminfo[smkx]} && ${+terminfo[rmkx]} )); then
226
+
autoload -Uz add-zle-hook-widget
227
+
function zle_application_mode_start { echoti smkx }
228
+
function zle_application_mode_stop { echoti rmkx }
229
+
add-zle-hook-widget -Uz zle-line-init zle_application_mode_start
230
+
add-zle-hook-widget -Uz zle-line-finish zle_application_mode_stop
233
+
## keybinding for convenient viewing of man pages
234
+
if test -x "${HOME}/bin/split-man"; then
235
+
split-man-widget() { "${HOME}/bin/split-man"}
236
+
zle -N split-man-widget
238
+
bindkey '^[m' split-man-widget
242
+
if test -x "$(command -v gumssh)"; then
243
+
bindkey -s '^[s' 'gumssh^M'
247
+
if test -x "$(command -v yazi)"; then
248
+
bindkey -s '^[f' 'yazi^M'
251
+
## history substring search
252
+
bindkey '^[[1;5A' history-substring-search-up
253
+
bindkey '^[[1;5B' history-substring-search-down
256
+
##############################################################################
258
+
##############################################################################
259
+
# Command checker helper
260
+
function check_cmd() {
261
+
test -x "$(command -v $1)"
264
+
## Nushell and jc functions
268
+
nu -c 'jc df | from json'
273
+
nu -c 'jc free | from json'
277
+
function netcons() {
278
+
nu -c 'jc lsof -i | from json'
283
+
nu -c 'jc ss -tulp | from json'
286
+
# nushell: openports
287
+
function openports() {
288
+
nu -c 'sudo jc lsof -i | from json | find "LISTEN"'
291
+
# nushell: list sockets in use
293
+
nu -c 'sudo jc lsof -i -P | from json'
297
+
function nuping() {
298
+
nu -c 'jc ping -c 3 $1 | from json'
303
+
nu -c 'jc ping -c 3 www.google.com | from json'
307
+
function nuptime() {
308
+
nu -c 'jc uptime | from json'
311
+
# nushell: os-release
312
+
function os-release() {
313
+
cat /etc/os-release | nu -c 'jc --os-release | from json'
316
+
# nushell: timestamp Z
318
+
nu -c 'date now | format date "%FT%T%:z"'
321
+
# watch directory listing, update every 0.1s
322
+
function watchdir() {
323
+
watch -n0,1 "ls -lh $1/ | tail"
326
+
# get time in timezone
327
+
function timein() {
328
+
continent=$(find /usr/share/zoneinfo -maxdepth 1 -mindepth 1 -type d -not -name "posix" -not -name "right" -exec basename {} \; | gum choose --limit=1)
329
+
city=$(find "/usr/share/zoneinfo/$continent" -type f -exec basename {} \; | gum choose --limit=1)
330
+
TZ="$continent/$city" date
333
+
# Generate a pseudo-random 16-character string.
334
+
function genrand() {
335
+
openssl rand -base64 16
338
+
# Remove ~/.ssh/known_hosts*
339
+
function rmknownhosts() {
340
+
rm -v "${HOME}/.ssh/known_hosts"*
343
+
# Copy SSH public key to clipboard (requires xclip -selection clipboard)
344
+
function pubkey() {
345
+
cat "${HOME}/.ssh/id_ed25519.pub" | tr -d '\n' | xclip -selection clipboard
346
+
echo "--> SSH public key copied to clipboard"
349
+
# Remove all .jpeg .jpg .png .svg .webp files from downloads
350
+
function rmpics() {
351
+
find "${HOME}/downloads" \
354
+
\( -name "*.jpg" -o -name "*.jpg_original" -o -name "*.jpeg" -o -name "*.svg" -o -name "*.png" -o -name "*.webp" \) \
358
+
# Remove all ISOs and disc images from downloads
359
+
function rmisos() {
360
+
find "${HOME}/downloads" \
363
+
\( -name "*.iso" -o -name "*.img" \) \
368
+
function ansplay() {
369
+
ansible-playbook -i inventory.yml "$@"
372
+
# Create a bookmark.
375
+
if ! test -f "${HOME}/.shellmarks"; then
376
+
touch "${HOME}/.shellmarks"
379
+
mark_to_add="$(pwd)"
381
+
if grep -qxFe "${mark_to_add}" "${HOME}/.shellmarks"; then
385
+
"This bookmark already exists: ${mark_to_add}"
387
+
echo "${mark_to_add}" >> "${HOME}/.shellmarks"
389
+
--foreground "#73F59F" \
391
+
"${mark_to_add} added to shellmarks file"
394
+
/bin/cat "${HOME}/.shellmarks" | sort | tee "${HOME}/.shellmarks" >/dev/null
400
+
function lsmarks() {
401
+
echo "# Shellmarks" | gum format
403
+
while IFS= read -r line; do
405
+
done < "${HOME}/.shellmarks" | gum format
408
+
# Remove bookmarks.
409
+
function delmark() {
410
+
selection=$(cat "${HOME}/.shellmarks" | gum choose --no-limit)
412
+
if test -n "${selection}"; then
413
+
while read -r line; do
414
+
perl -n -i -e "print unless /^\\Q${line//\//\\/}\\E\$/" "${HOME}/.shellmarks"
415
+
done <<< "${selection}"
420
+
gum format -t markdown -- \
421
+
"# The following bookmarks were deleted:" \
422
+
"$(printf "%s\n" "${selection}")"
428
+
function gotomark() {
429
+
if ! test -f "${HOME}/.shellmarks"; then
430
+
echo "No bookmarks exist yet. Add some!"
435
+
builtin cd $(cat "${HOME}/.shellmarks" | gum choose --limit=1 --height=20)
438
+
for precmd in $precmd_functions; do
441
+
zle && zle reset-prompt
444
+
bindkey '^[g' gotomark
446
+
# Choose a directory from the directory stack.
447
+
function dstack() {
448
+
echo "# Choose a directory" | gum format -t markdown
449
+
selection=$(dirs -lp | gum choose --limit=1)
453
+
# Print timestamp as %Y-%m-%d %H:%M:%S.
454
+
function tstamp() {
456
+
date '+%Y-%m-%d %H:%M:%S' | tr -d '\n'
459
+
# Print timestamp as %Y-%m-%dT%H:%M:%S%:z
460
+
function tstampz() {
462
+
date '+%Y-%m-%dT%H:%M:%S%:z' | tr -d '\n'
465
+
# zrmcomp() remove *.zwc files.
466
+
function zrmcomp() {
468
+
for i in ${HOME}/*.zwc(N); do
469
+
printf "Removing $i\n"
474
+
# Invoke this every time you change .zshrc to recompile it.
476
+
autoload -U zrecompile
477
+
[ -f ~/.zshrc ] && zrecompile -p ~/.zshrc
478
+
[ -f ~/.zcompdump ] && zrecompile -p ~/.zcompdump
479
+
[ -f ~/.zcompdump ] && zrecompile -p ~/.zcompdump
480
+
[ -f ~/.zshrc.zwc.old ] && command rm -f ~/.zshrc.zwc.old
481
+
[ -f ~/.zcompdump.zwc.old ] && command rm -f ~/.zcompdump.zwc.old
485
+
# Do an ls after cd.
486
+
function cd() { builtin cd "$@" && ls; }
488
+
# Create new directory and enter it.
489
+
function mkd() { mkdir -p "$@" && cd "$_"; }
491
+
# Display pids of commands.
492
+
function pids() { pgrep -a "$@"; }
495
+
function restart() { exec $SHELL $SHELL_ARGS "$@"; }
497
+
# cd to ~, clear screen, and restart zsh.
498
+
function rsrc() { cd && clear && restart; }
501
+
# Usage: newfeelslog <tag0> <tag1> ... <tagN>
502
+
function newfeelslog() {
503
+
DATE=$(date '+%Y-%m-%d')
504
+
FEELSDIR="${HOME}/Nextcloud/sites/feels.hyperreal.coffee"
505
+
PREV_ENTRY=$(find "$FEELSDIR/src" -name "*.md" -exec basename {} \; | sort | tail -1 | cut -c 18-21)
506
+
NEXT_ENTRY="00$(echo "$PREV_ENTRY" + "1" | bc)"
507
+
NEXT_ENTRY_FILENAME="${FEELSDIR}/src/${DATE}-entry-${NEXT_ENTRY}.md"
509
+
cat <<EOF >"$NEXT_ENTRY_FILENAME"
511
+
title: Entry $NEXT_ENTRY
512
+
date: $(date '+%Y-%m-%d %H:%M:%S %z')
514
+
slug: entry-$NEXT_ENTRY
518
+
$EDITOR "$NEXT_ENTRY_FILENAME"
523
+
##############################################################################
525
+
##############################################################################
527
+
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
529
+
export FZF_DEFAULT_OPTS='--color=bg+:#302D41,bg:#1E1E2E,spinner:#F8BD96,hl:#F28FAD --color=fg:#D9E0EE,header:#F28FAD,info:#DDB6F2,pointer:#F8BD96 --color=marker:#F8BD96,fg+:#F2CDCD,prompt:#DDB6F2,hl+:#F28FAD'
531
+
## completion trigger
532
+
export FZF_COMPLETION_TRIGGER="~~"
534
+
## default source for fzf
535
+
export FZF_DEFAULT_COMMAND="fd --type f --hidden --follow --exclude .git"
538
+
# CTRL-Y to copy the command into clipboard using wl-copy
539
+
export FZF_CTRL_R_OPTS="
540
+
--bind 'ctrl-y:execute-silent(echo -n {2..} | wl-copy)+abort'
541
+
--color header:italic
542
+
--header 'Press CTRL-Y to copy command into clipboard'"
545
+
##############################################################################
547
+
##############################################################################
549
+
## General shell options
550
+
# See https://zsh-manual.netlify.app/options
552
+
# This is a multiple move based on zsh pattern matching (like "mmv").
553
+
# Read ``less ${^fpath}/zmv(N)'' for more details.
556
+
# A builtin that can clone a running shell onto another terminal.
557
+
zmodload -e zsh/clone
559
+
# When listing options (by 'setopt', 'unsetopt', 'set -o', or 'set +o'),
560
+
# those turned on by default appear in the list prefixed with 'no'.
561
+
# Hence (unless KSH_OPTION_PRINT is set), 'setopt' shows all options whose
562
+
# settings are changed from default.
564
+
# Report the status of background jobs immediately, rather than waiting until
565
+
# just before printing a prompt.
568
+
# Allow comments even in interactive shells.
569
+
setopt interactivecomments
571
+
# Send *not* a HUP signal to running jobs when the shell exits.
574
+
# If a pattern for filename generation has no matches, delete the pattern from
575
+
# the argument list instead of reporting an error.
576
+
# Overrides NOMATCH
579
+
# Perform =filename access
583
+
# $ unsetopt EQUALS
586
+
# NOTE: It's not really needed because zsh sets the per default.
589
+
# Try to make completion list smaller by printing the matches in columns with
590
+
# different widths.
593
+
# Expands single letters and ranges of letters between braces
594
+
# $ print 1{abw-z}2
595
+
# $ 1a2 1b2 1w2 1y2 1z2
598
+
# If the argument to a cd command (or an implied cd with the AUTO_CD option
599
+
# set) is not a directory, and does not begin with a slash, try to expand the
600
+
# expression as if it were preceded by a '~' (See section 14.7 Filename
604
+
# Report the status of background and suspended jobs before exiting a shell
605
+
# with job control; a second attempt to exit the shell will succeed.
608
+
# Make cd push the old directory onto the directory stack.
611
+
# Change to directory without cd
614
+
# Query the user before executing 'rm *' or 'rm path/*'
615
+
setopt normstarsilent
616
+
setopt no_rm_star_wait
618
+
# Shaddapa you face
621
+
# When writing out the history file, older commands that duplicate newer ones
625
+
# When searching for history entries in the line editor, do not display
626
+
# duplicates of a line previously found, even if the duplicates are not
628
+
setopt histfindnodups
630
+
# If the internal history needs to be trimmed to add the current command line,
631
+
# setting this option will cause the oldest history event that has a duplicate
632
+
# to be lost before losing a unique event from the list.
633
+
setopt hist_expire_dups_first
635
+
# If a new command line being added to the history list duplicates an older
636
+
# one, the older command is removed from the list (even if it is not the
638
+
setopt hist_ignore_all_dups
640
+
# Do not enter command lines into the history list if they are duplicates of
641
+
# the previous event.
642
+
setopt hist_ignore_dups
644
+
# Remove superfluous blanks from each command line being added to history.
645
+
setopt hist_reduce_blanks
647
+
# Whenever the user enters a line with history expansion, don't execute the
648
+
# line directly; instead, perform history expansion and reload the line into
649
+
# the editing buffer.
652
+
# Do not remove function definitions from the history list.
653
+
unsetopt hist_no_functions
655
+
# Remove the history (fc -l) command from the history list when invoked.
656
+
# Note that the command lingers in the internal history until the next command
657
+
# is entered before it vanishes, allowing you to briefly reuse or edit the
659
+
setopt hist_no_store
661
+
# If this is set, zsh sessions will append their history list to the history
662
+
# file, rather than overwrite it. Thus, multiple parallel zsh sessions will all
663
+
# have their history lists added to the history file, in the order they are
665
+
setopt appendhistory
667
+
# If unset, the cursor is set to the end of the word if completion is started.
668
+
# Otherwise, it stays there and completion is done from both ends.
669
+
unsetopt completeinword
671
+
# When listing files that are possible completions, show the type of each file
672
+
# with a trailing identifying mark.
675
+
# Do not require a leading '.' in a filename to be matched explicitly.
678
+
# List jobs in long format by default
679
+
setopt longlistjobs
681
+
# Don't push multiple copies of the same directory onto the directory staack.
682
+
setopt pushdignoredups
684
+
# This option both imports new commands from the history file, and also causes
685
+
# your typed commands to be appended to the history file (the latter is like
686
+
# specifying INC_APPEND_HISTORY).
687
+
# The history lines are also output with timestamps ala EXTENDED_HISTORY
688
+
# (which makes it easier to find the spot where we left off reading the file
689
+
# after it gets re-written).
690
+
setopt sharehistory
692
+
# Save each command's beginning timestamp (in seconds since the epoch)
693
+
# and the duration (in seconds) to the history file. The format of this
694
+
# prefixed data is:
695
+
# ':<beginning time>:<elapsed seconds>;<command>'
696
+
setopt extendedhistory
698
+
# Do *not* run all background jobs at a lower nice priority
702
+
##############################################################################
703
+
# CATPPUCCIN SYNTAX HIGHLIGHTING
704
+
##############################################################################
705
+
# Catppuccin Mocha Theme (for zsh-syntax-highlighting)
707
+
# Paste this files contents inside your ~/.zshrc before you activate zsh-syntax-highlighting
708
+
ZSH_HIGHLIGHT_HIGHLIGHTERS=(main cursor)
709
+
typeset -gA ZSH_HIGHLIGHT_STYLES
711
+
# Main highlighter styling: https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters/main.md
718
+
ZSH_HIGHLIGHT_STYLES[comment]='fg=#585b70'
721
+
## Functions/methods
722
+
ZSH_HIGHLIGHT_STYLES[alias]='fg=#a6e3a1'
723
+
ZSH_HIGHLIGHT_STYLES[suffix-alias]='fg=#a6e3a1'
724
+
ZSH_HIGHLIGHT_STYLES[global-alias]='fg=#a6e3a1'
725
+
ZSH_HIGHLIGHT_STYLES[function]='fg=#a6e3a1'
726
+
ZSH_HIGHLIGHT_STYLES[command]='fg=#a6e3a1'
727
+
ZSH_HIGHLIGHT_STYLES[precommand]='fg=#a6e3a1,italic'
728
+
ZSH_HIGHLIGHT_STYLES[autodirectory]='fg=#fab387,italic'
729
+
ZSH_HIGHLIGHT_STYLES[single-hyphen-option]='fg=#fab387'
730
+
ZSH_HIGHLIGHT_STYLES[double-hyphen-option]='fg=#fab387'
731
+
ZSH_HIGHLIGHT_STYLES[back-quoted-argument]='fg=#cba6f7'
734
+
ZSH_HIGHLIGHT_STYLES[builtin]='fg=#a6e3a1'
735
+
ZSH_HIGHLIGHT_STYLES[reserved-word]='fg=#a6e3a1'
736
+
ZSH_HIGHLIGHT_STYLES[hashed-command]='fg=#a6e3a1'
738
+
ZSH_HIGHLIGHT_STYLES[commandseparator]='fg=#f38ba8'
739
+
ZSH_HIGHLIGHT_STYLES[command-substitution-delimiter]='fg=#cdd6f4'
740
+
ZSH_HIGHLIGHT_STYLES[command-substitution-delimiter-unquoted]='fg=#cdd6f4'
741
+
ZSH_HIGHLIGHT_STYLES[process-substitution-delimiter]='fg=#cdd6f4'
742
+
ZSH_HIGHLIGHT_STYLES[back-quoted-argument-delimiter]='fg=#f38ba8'
743
+
ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]='fg=#f38ba8'
744
+
ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument]='fg=#f38ba8'
745
+
## Serializable / Configuration Languages
748
+
ZSH_HIGHLIGHT_STYLES[command-substitution-quoted]='fg=#f9e2af'
749
+
ZSH_HIGHLIGHT_STYLES[command-substitution-delimiter-quoted]='fg=#f9e2af'
750
+
ZSH_HIGHLIGHT_STYLES[single-quoted-argument]='fg=#f9e2af'
751
+
ZSH_HIGHLIGHT_STYLES[single-quoted-argument-unclosed]='fg=#eba0ac'
752
+
ZSH_HIGHLIGHT_STYLES[double-quoted-argument]='fg=#f9e2af'
753
+
ZSH_HIGHLIGHT_STYLES[double-quoted-argument-unclosed]='fg=#eba0ac'
754
+
ZSH_HIGHLIGHT_STYLES[rc-quote]='fg=#f9e2af'
756
+
ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]='fg=#cdd6f4'
757
+
ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument-unclosed]='fg=#eba0ac'
758
+
ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]='fg=#cdd6f4'
759
+
ZSH_HIGHLIGHT_STYLES[assign]='fg=#cdd6f4'
760
+
ZSH_HIGHLIGHT_STYLES[named-fd]='fg=#cdd6f4'
761
+
ZSH_HIGHLIGHT_STYLES[numeric-fd]='fg=#cdd6f4'
762
+
## No category relevant in spec
763
+
ZSH_HIGHLIGHT_STYLES[unknown-token]='fg=#eba0ac'
764
+
ZSH_HIGHLIGHT_STYLES[path]='fg=#cdd6f4,underline'
765
+
ZSH_HIGHLIGHT_STYLES[path_pathseparator]='fg=#f38ba8,underline'
766
+
ZSH_HIGHLIGHT_STYLES[path_prefix]='fg=#cdd6f4,underline'
767
+
ZSH_HIGHLIGHT_STYLES[path_prefix_pathseparator]='fg=#f38ba8,underline'
768
+
ZSH_HIGHLIGHT_STYLES[globbing]='fg=#cdd6f4'
769
+
ZSH_HIGHLIGHT_STYLES[history-expansion]='fg=#cba6f7'
770
+
#ZSH_HIGHLIGHT_STYLES[command-substitution]='fg=?'
771
+
#ZSH_HIGHLIGHT_STYLES[command-substitution-unquoted]='fg=?'
772
+
#ZSH_HIGHLIGHT_STYLES[process-substitution]='fg=?'
773
+
#ZSH_HIGHLIGHT_STYLES[arithmetic-expansion]='fg=?'
774
+
ZSH_HIGHLIGHT_STYLES[back-quoted-argument-unclosed]='fg=#eba0ac'
775
+
ZSH_HIGHLIGHT_STYLES[redirection]='fg=#cdd6f4'
776
+
ZSH_HIGHLIGHT_STYLES[arg0]='fg=#cdd6f4'
777
+
ZSH_HIGHLIGHT_STYLES[default]='fg=#cdd6f4'
778
+
ZSH_HIGHLIGHT_STYLES[cursor]='fg=#cdd6f4'