added stuff

This commit is contained in:
vali 2024-04-09 23:11:33 +02:00
commit 7d4f626b7d
907 changed files with 70990 additions and 0 deletions

View file

@ -0,0 +1,70 @@
{
pkgs,
lib,
...
}: let
inherit (lib.meta) getExe getExe';
inherit (pkgs) eza bat ripgrep du-dust procs yt-dlp python3 netcat-gnu;
dig = getExe' pkgs.dnsutils "dig";
in {
programs.zsh.shellAliases = {
# make sudo use aliases
sudo = "sudo ";
# easy netcat alias for my fiche host
# https://github.com/solusipse/fiche
fbin = "${getExe netcat-gnu} p.frzn.dev 9999";
# nix specific aliases
cleanup = "sudo nix-collect-garbage --delete-older-than 3d && nix-collect-garbage -d";
bloat = "nix path-info -Sh /run/current-system";
curgen = "sudo nix-env --list-generations --profile /nix/var/nix/profiles/system";
gc-check = "nix-store --gc --print-roots | egrep -v \"^(/nix/var|/run/\w+-system|\{memory|/proc)\"";
repair = "nix-store --verify --check-contents --repair";
run = "nix run";
search = "nix search";
shell = "nix shell";
build = "nix build $@ --builders \"\"";
# quality of life aliases
cat = "${getExe bat} --style=plain";
grep = "${getExe ripgrep}";
du = "${getExe du-dust}";
ps = "${getExe procs}";
mp = "mkdir -p";
fcd = "cd $(find -type d | fzf)";
ls = "${getExe eza} -h --git --icons --color=auto --group-directories-first -s extension";
l = "ls -lF --time-style=long-iso --icons";
ytmp3 = ''
${getExe yt-dlp} -x --continue --add-metadata --embed-thumbnail --audio-format mp3 --audio-quality 0 --metadata-from-title="%(artist)s - %(title)s" --prefer-ffmpeg -o "%(title)s.%(ext)s"
'';
# system aliases
sc = "sudo systemctl";
jc = "sudo journalctl";
scu = "systemctl --user ";
jcu = "journalctl --user";
la = "${getExe eza} -lah --tree";
tree = "${getExe eza} --tree --icons=always";
http = "${getExe python3} -m http.server";
burn = "pkill -9";
diff = "diff --color=auto";
killall = "pkill";
switch-yubikey = "gpg-connect-agent \"scd serialno\" \"learn --force\" /bye";
# insteaed of querying some weird and random"what is my ip" service
# we get our public ip by querying opendns directly.
# <https://unix.stackexchange.com/a/81699>
canihazip = "${dig} @resolver4.opendns.com myip.opendns.com +short";
canihazip4 = "${dig} @resolver4.opendns.com myip.opendns.com +short -4";
canihazip6 = "${dig} @resolver1.ipv6-sandbox.opendns.com AAAA myip.opendns.com +short -6";
# faster navigation
".." = "cd ..";
"..." = "cd ../../";
"...." = "cd ../../../";
"....." = "cd ../../../../";
"......" = "cd ../../../../../";
};
}

View file

@ -0,0 +1,53 @@
{config, ...}: {
imports = [
./aliases.nix
./init.nix
./plugins.nix
];
config = {
programs.zsh = {
enable = true;
dotDir = ".config/zsh";
enableCompletion = true;
autosuggestion.enable = true;
syntaxHighlighting.enable = true;
sessionVariables = {LC_ALL = "en_US.UTF-8";};
history = {
# share history between different zsh sessions
share = true;
# avoid cluttering $HOME with the histfile
path = "${config.xdg.dataHome}/zsh/zsh_history";
# saves timestamps to the histfile
extended = true;
# optimize size of the histfile by avoiding duplicates
# or commands we don't need remembered
save = 100000;
size = 100000;
expireDuplicatesFirst = true;
ignoreDups = true;
ignoreSpace = true;
ignorePatterns = ["rm *" "pkill *" "kill *" "killall *"];
};
# dirhashes are easy aliases to commonly used directoryies
# e.g. `cd ~dl` would take you to $HOME/Downloads
dirHashes = {
docs = "$HOME/Documents";
dl = "$HOME/Downloads";
media = "$HOME/Media";
vids = "$HOME/Media/Videos";
music = "$HOME/Media/Music";
pics = "$HOME/Media/Pictures";
screenshots = "$HOME/Media/Pictures/Screenshots";
notes = "$HOME/Cloud/Notes";
dev = "$HOME/Dev";
dots = "$HOME/.config/nyx";
};
};
};
}

View file

@ -0,0 +1,71 @@
{
osConfig,
lib,
...
}: let
inherit (builtins) readFile;
inherit (lib.strings) fileContents;
inherit (osConfig.modules.style.colorScheme) colors;
in {
programs.zsh = {
completionInit = ''
${readFile ./rc/comp.zsh}
${readFile ./rc/fzf.zsh}
# configure fzf tab options
export FZF_DEFAULT_OPTS="
--color gutter:-1
--color bg:-1
--color bg+:-1
--color fg:#${colors.base04}
--color fg+:#${colors.base06}
--color hl:#${colors.base0D}
--color hl+:#${colors.base0D}
--color header:#${colors.base0D}
--color info:#${colors.base0A}
--color marker:#${colors.base0C}
--color pointer:#${colors.base0C}
--color prompt:#${colors.base0A}
--color spinner:#${colors.base0C}
--color preview-bg:#${colors.base01}
--color preview-fg:#${colors.base0D}
--prompt ' '
--pointer ''
--layout=reverse
-m --bind ctrl-space:toggle,pgup:preview-up,pgdn:preview-down
"
'';
initExtra = ''
# avoid duplicated entries in PATH
typeset -U PATH
# try to correct the spelling of commands
setopt correct
# disable C-S/C-Q
setopt noflowcontrol
# disable "no matches found" check
unsetopt nomatch
# my helper functions for setting zsh options that I normally use on my shell
# a description of each option can be found in the Zsh manual
# <https://zsh.sourceforge.io/Doc/Release/Options.html>
# NOTE: this slows down shell startup time considerably
${fileContents ./rc/unset.zsh}
${fileContents ./rc/set.zsh}
# binds, zsh modules and everything else
${fileContents ./rc/binds.zsh}
${fileContents ./rc/modules.zsh}
${fileContents ./rc/misc.zsh}
'';
initExtraFirst = ''
# Do this early so fast-syntax-highlighting can wrap and override this
if autoload history-search-end; then
zle -N history-beginning-search-backward-end history-search-end
zle -N history-beginning-search-forward-end history-search-end
fi
'';
};
}

View file

@ -0,0 +1,35 @@
{pkgs, ...}: let
inherit (pkgs) fetchFromGitHub;
in {
programs.zsh.plugins = [
{
# Must be before plugins that wrap widgets, such as zsh-autosuggestions or fast-syntax-highlighting
name = "fzf-tab";
src = "${pkgs.zsh-fzf-tab}/share/fzf-tab";
}
{
name = "zsh-nix-shell";
src = pkgs.zsh-nix-shell;
file = "share/zsh-nix-shell/nix-shell.plugin.zsh";
}
{
name = "zsh-vi-mode";
src = pkgs.zsh-vi-mode;
file = "share/zsh-vi-mode/zsh-vi-mode.plugin.zsh";
}
{
name = "fast-syntax-highlighting";
src = "${pkgs.zsh-fast-syntax-highlighting}/share/zsh/site-functions";
}
{
name = "zsh-autopair";
file = "zsh-autopair.plugin.zsh";
src = fetchFromGitHub {
owner = "hlissner";
repo = "zsh-autopair";
rev = "2ec3fd3c9b950c01dbffbb2a4d191e1d34b8c58a";
hash = "sha256-Y7fkpvCOC/lC2CHYui+6vOdNO8dNHGrVYTGGNf9qgdg=";
};
}
];
}

View file

@ -0,0 +1,11 @@
# Enable Vi mode
bindkey -v
# Use vim keys in the tab complete menu
bindkey -M menuselect 'h' vi-backward-char
bindkey -M menuselect 'k' vi-up-line-or-history
bindkey -M menuselect 'l' vi-forward-char
bindkey -M menuselect 'j' vi-down-line-or-history
bindkey "^A" vi-beginning-of-line
bindkey "^E" vi-end-of-line

View file

@ -0,0 +1,95 @@
# Completion
# autoload -U compinit
zstyle ':completion:*' menu select
zmodload zsh/complist
compinit -d "$XDG_CACHE_HOME"/zsh/zcompdump-"$ZSH_VERSION"
_comp_options+=(globdots)
# Group matches and describe.
zstyle ':completion:*' sort false
zstyle ':completion:complete:*:options' sort false
zstyle ':completion:*' matcher-list 'm:{[:lower:][:upper:]}={[:upper:][:lower:]}' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]} l:|=* r:|=*' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]} l:|=* r:|=*' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]} l:|=* r:|=*'
zstyle ':completion:*' special-dirs true
zstyle ':completion:*' rehash true
# Sort completions
# disable sort when completing `git checkout`
zstyle ':completion:*:git-checkout:*' sort false
# set descriptions format to enable group support
zstyle ':completion:*:descriptions' format '[%d]'
# set list-colors to enable filename colorizing
zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
# preview directory's content when completing cd
zstyle ':fzf-tab:complete:cd:*' fzf-preview 'ls -lAhF --group-directories-first --show-control-chars --quoting-style=escape --color=always $realpath'
zstyle ':fzf-tab:complete:cd:*' popup-pad 20 0
zstyle ':completion:*' file-sort modification
zstyle ':completion:*:eza' sort false
zstyle ':completion:files' sort false
# Job IDs
zstyle ':completion:*:jobs' numbers true
zstyle ':completion:*:jobs' verbose true
# Array completion element sorting.
zstyle ':completion:*:*:-subscript-:*' tag-order indexes parameters
# Don't complete unavailable commands.
zstyle ':completion:*:functions' ignored-patterns '(_*|pre(cmd|exec))'
# No correction
zstyle ':completion:*' completer _oldlist _expand _complete _files _ignored
# Don't insert tabs when there is no completion (e.g. beginning of line)
zstyle ':completion:*' insert-tab false
# allow one error for every three characters typed in approximate completer
zstyle ':completion:*:approximate:' max-errors 'reply=( $((($#PREFIX+$#SUFFIX)/3 )) numeric )'
# start menu completion only if it could find no unambiguous initial string
zstyle ':completion:*:correct:*' insert-unambiguous true
zstyle ':completion:*:corrections' format $'%{\e[0;31m%}%d (errors: %e)%{\e[0m%}'
zstyle ':completion:*:correct:*' original true
# List directory completions first
zstyle ':completion:*' list-dirs-first true
# Offer the original completion when using expanding / approximate completions
zstyle ':completion:*' original true
# Treat multiple slashes as a single / like UNIX does (instead of as /*/)
zstyle ':completion:*' squeeze-slashes true
# insert all expansions for expand completer
# # ???????????????ßß
zstyle ':completion:*:expand:*' tag-order all-expansions
# match uppercase from lowercase
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}'
# separate matches into groups
zstyle ':completion:*:matches' group 'yes'
zstyle ':completion:*' group-name ''
zstyle ':completion:*:messages' format '%d'
zstyle ':completion:*:options' auto-description '%d'
# describe options in full
zstyle ':completion:*:options' description 'yes'
# on processes completion complete all user processes
zstyle ':completion:*:processes' command 'ps -au$USER'
# provide verbose completion information
zstyle ':completion:*' verbose true
# Ignore completion functions for commands you don't have:
zstyle ':completion::(^approximate*):*:functions' ignored-patterns '_*'
# Provide more processes in completion of programs like killall:
zstyle ':completion:*:processes-names' command 'ps c -u ${USER} -o command | uniq'
# complete manual by their section
zstyle ':completion:*:manuals' separate-sections true
zstyle ':completion:*:manuals.*' insert-sections true
zstyle ':completion:*:man:*' menu yes select
# provide .. as a completion
zstyle ':completion:*' special-dirs ..

View file

@ -0,0 +1,73 @@
autoload -U add-zle-hook-widget
# autosuggests otherwise breaks these widgets.
# <https://github.com/zsh-users/zsh-autosuggestions/issues/619>
ZSH_AUTOSUGGEST_CLEAR_WIDGETS+=(history-beginning-search-backward-end history-beginning-search-forward-end)
# FZF widgets
function __fzf() {
if [[ -n "$TMUX_PANE" && ( "${FZF_TMUX:-0}" != 0 || -n "$FZF_TMUX_OPTS" ) ]]; then
fzf-tmux -d"${FZF_TMUX_HEIGHT:-40%}" -- "$@"
else
fzf "$@"
fi
}
function __fzf_select() {
setopt localoptions pipefail no_aliases 2>/dev/null
local item
FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse --bind=ctrl-z:ignore,tab:down,btab:up,change:top,ctrl-space:toggle $FZF_DEFAULT_OPTS" __fzf "$@" | while read item; do
echo -n "${(q)item} "
done
local ret=$?
echo
return $ret
}
function __fzf_find_files() {
local include_hidden=${1:-0}
local types=${2:-fdl}
shift 2
local type_selectors=()
local i
for (( i=0; i<${#types}; i++ )); do
[[ "$i" -gt 0 ]] && type_selectors+=('-o')
type_selectors+=('-type' "${types:$i:1}")
done
local hide_hidden_files=()
if [[ $include_hidden == "0" ]]; then
hide_hidden_files=('-path' '*/\.*' '-o')
fi
setopt localoptions pipefail no_aliases 2>/dev/null
command find -L . -mindepth 1 \
\( "${hide_hidden_files[@]}" -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \) -prune \
-o \( "${type_selectors[@]}" \) -print \
| __fzf_select "$@"
}
function __fzf_find_files_widget_helper() {
LBUFFER="${LBUFFER}$(__fzf_find_files "$@")"
local ret=$?
zle reset-prompt
return $ret
}
function fzf-select-file-or-dir() { __fzf_find_files_widget_helper 0 fdl -m; }; zle -N fzf-select-file-or-dir
function fzf-select-file-or-dir-hidden() { __fzf_find_files_widget_helper 1 fdl -m; }; zle -N fzf-select-file-or-dir-hidden
function fzf-select-dir() { __fzf_find_files_widget_helper 0 d -m; }; zle -N fzf-select-dir
function fzf-select-dir-hidden() { __fzf_find_files_widget_helper 1 d -m; }; zle -N fzf-select-dir-hidden
function fzf-cd() {
local dir="$(__fzf_find_files 0 d +m)"
if [[ -z "$dir" ]]; then
zle redisplay
return 0
fi
zle push-line # Clear buffer. Auto-restored on next prompt.
BUFFER="cd -- $dir"
zle accept-line
local ret=$?
unset dir # ensure this doesn't end up appearing in prompt expansion
zle reset-prompt
return $ret
}
zle -N fzf-cd

View file

@ -0,0 +1,22 @@
# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*|Eterm|aterm|kterm|gnome*|alacritty|kitty*)
TERM_TITLE=$'\e]0;%n@%m: %1~\a'
;;
*)
;;
esac
# enable keyword-style arguments in shell functions
set -k
# Colors
autoload -Uz colors && colors
# Autosuggest
ZSH_AUTOSUGGEST_USE_ASYNC="true"
# open commands in $EDITOR
autoload -z edit-command-line
zle -N edit-command-line
bindkey "^e" edit-command-line

View file

@ -0,0 +1,8 @@
# zsh Line Editor (ZLE) module
zmodload zsh/zle
# zsh pseudo-terminal (PTY) module
zmodload zsh/zpty
# zsh completion list (complist) module
zmodload zsh/complist

View file

@ -0,0 +1,31 @@
# Define a function to set Zsh options
function set_zsh_options() {
local options=(
"AUTO_CD" # if not command, then directory
"AUTO_LIST" # list choices on ambiguous completion
"AUTO_MENU" # use menu completion after the second consecutive request for completion
"AUTO_PARAM_SLASH" # if parameter is completed whose content is the name of a directory, then add trailing slash instead of space
"AUTO_PUSHD" # make cd push the old directory onto the directory stack
"APPEND_HISTORY" # append history list to the history file, rather than replace it
"ALWAYS_TO_END" # cursor is moved to the end of the word after completion
"CORRECT" # try to correct the spelling of commands
"EXTENDED_HISTORY" # save each commands beginning timestamp and the duration to the history file
"HIST_FCNTL_LOCK" # use systems fcntl call to lock the history file
"HIST_REDUCE_BLANKS" # remove superfluous blanks
"HIST_SAVE_NO_DUPS" # older commands that duplicate newer ones are omitted
"HIST_VERIFY" # dont execute the line directly; instead perform history expansion and reload the line into the editing buffer
"INC_APPEND_HISTORY" # new history lines are added to the $HISTFILE incrementally (as soon as they are entered)
"INTERACTIVE_COMMENTS" # allow comments even in interactive shells
"MENU_COMPLETE" # insert the first match immediately on ambiguous completion
"NO_NOMATCH" # not explained, probably disables NOMATCH lmao
"PUSHD_IGNORE_DUPS" # dont push multiple copies of the same directory
"PUSHD_TO_HOME" # have pushd with no arguments act like `pushd $HOME`
"PUSHD_SILENT" # do not print the directory stack
)
for option in "${options[@]}"; do
setopt $option
done
}
set_zsh_options

View file

@ -0,0 +1,14 @@
# Define a function to unset Zsh options
function unset_zsh_options() {
local options=(
"CORRECT_ALL" # try to correct the spelling of all arguments in a line.
"HIST_BEEP" # beep in ZLE when a widget attempts to access a history entry which isnt there
"SHARE_HISTORY" # read the documentation for more details
)
for option in "${options[@]}"; do
unsetopt $option
done
}
unset_zsh_options