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,22 @@
{
programs.bash = {
enable = false;
enableCompletion = true;
bashrcExtra = ''
set -o vi
bind -m vi-command 'Control-l: clear-screen'
bind -m vi-insert 'Control-l: clear-screen'
bind 'set show-mode-in-prompt on'
bind 'set vi-cmd-mode-string "n "'
bind 'set vi-ins-mode-string "i "'
# use ctrl-z to toggle in and out of bg
if [[ $- == *i* ]]; then
stty susp undef
bind -m vi-command 'Control-z: fg\015'
bind -m vi-insert 'Control-z: fg\015'
fi
'';
};
}

View file

@ -0,0 +1,115 @@
#!/usr/bin/env bash
# Function to compile and run a single .cpp file
function compile_and_run_file() {
filename="$1"
basename="''${filename%.*}"
echo "Compiling $filename..."
if g++ -o "$basename" "$filename"; then
echo "Running $basename..."
"./$basename"
else
echo "Compilation failed."
fi
}
# Function to prompt user to choose a .cpp file using skim or fzf
function choose_cpp_file() {
directory="$1"
if command -v skim >/dev/null 2>&1; then
file=$(find "$directory" -maxdepth 1 -type f -name "*.cpp" | skim --ansi --query "")
elif command -v fzf >/dev/null 2>&1; then
file=$(find "$directory" -maxdepth 1 -type f -name "*.cpp" | fzf)
else
echo "Error: skim or fzf is required for file selection."
exit 1
fi
if [ -n "$file" ]; then
compile_and_run_file "$file"
else
echo "No .cpp file selected."
fi
}
# Function to prompt user to choose a .cpp file recursively using skim or fzf
function choose_cpp_file_recursive() {
directory="$1"
if command -v skim >/dev/null 2>&1; then
file=$(find "$directory" -type f -name "*.cpp" | sk --ansi --query "")
elif command -v fzf >/dev/null 2>&1; then
file=$(find "$directory" -type f -name "*.cpp" | fzf)
else
echo "Error: skim or fzf is required for file selection."
exit 1
fi
if [ -n "$file" ]; then
compile_and_run_file "$file"
else
echo "No .cpp file selected."
fi
}
# Help menu
function display_help() {
echo "Usage: $0 [options] <file/directory>"
echo "Options:"
echo " --recursive Look for .cpp files recursively"
echo " --help Display this help menu"
echo
echo "Examples:"
echo " $0 ~/Dev/test.cpp"
echo " $0 ~/Dev"
echo " $0 ~/Dev --recursive"
}
# Parse command line arguments
recursive=false
directory=""
# Check if --help is passed
if [[ $1 == "--help" ]]; then
display_help
exit 0
fi
while [[ $# -gt 0 ]]; do
case "$1" in
--recursive)
recursive=true
shift
;;
*)
directory="$1"
shift
;;
esac
done
# Check if directory is provided
if [ -z "$directory" ]; then
echo "Error: No directory specified."
display_help
exit 1
fi
# Check if directory exists
if [ ! -d "$directory" ]; then
echo "Error: Directory does not exist."
display_help
exit 1
fi
# Compile and run or display help menu
if [ -f "$directory" ]; then
compile_and_run_file "$directory"
elif [ "$recursive" = true ]; then
choose_cpp_file_recursive "$directory"
else
choose_cpp_file "$directory"
fi

View file

@ -0,0 +1,94 @@
{
config,
pkgs,
lib,
...
}: let
inherit (lib) getExe;
inherit (builtins) readFile;
in {
home = {
# make sure the scripts linked below in the session PATH
# so that they can be referred to by name
sessionPath = ["${config.home.homeDirectory}/.local/bin"];
# link scripts to the local PATH
file = {
".local/bin/preview" = {
# Preview script for fzf tab
source = getExe (pkgs.writeShellApplication {
name = "preview";
runtimeInputs = with pkgs; [fzf eza catimg];
text = readFile ./preview/preview.sh;
});
};
".local/bin/show-zombie-parents" = {
# Show zombie processes and their parents
source = getExe (pkgs.writeShellApplication {
name = "show-zombie-parents";
runtimeInputs = with pkgs; [fzf eza catimg];
text = readFile ./show-zombie-parents/show-zombie-parents.sh;
});
};
".local/bin/tzip" = {
# Find all latest .tmod files recursively in current directory and zip them
# for tmodloader mods downloaded via steam workshop
source = getExe (pkgs.writeShellApplication {
name = "tzip";
runtimeInputs = with pkgs; [zip];
text = readFile ./tzip/tzip.sh;
});
};
".local/bin/extract" = {
# Extract the compressed file with the correct tool based on the extension
source = getExe (pkgs.writeShellApplication {
name = "extract";
runtimeInputs = with pkgs; [zip unzip gnutar p7zip];
text = readFile ./extract/extract.sh;
});
};
".local/bin/compilec" = {
# Interactively find and compile C++ programs
source = getExe (pkgs.writeShellApplication {
name = "compilec";
runtimeInputs = with pkgs; [skim coreutils gcc];
text = readFile ./compilec/compilec.sh;
});
};
".local/bin/fs-diff" = {
# Show diff of two directories
source = getExe (pkgs.writeShellApplication {
name = "fs-diff";
runtimeInputs = with pkgs; [coreutils gnused btrfs-progs];
text = readFile ./fs-diff/fs-diff.sh;
});
};
".local/bin/purge-direnv" = {
# Purge all direnv links
source = getExe (pkgs.writeShellApplication {
name = "purge-direnv";
runtimeInputs = with pkgs; [direnv];
text = readFile ./purge-direnv/purge-direnv.sh;
});
};
".local/bin/addr" = {
# Get external IP address
source = getExe (pkgs.writeShellApplication {
name = "addr";
runtimeInputs = with pkgs; [curl];
text = ''
#!${pkgs.stdenv.shell}
exec curl "$@" icanhazip.com
'';
});
};
};
};
}

View file

@ -0,0 +1,52 @@
#!/usr/bin/env bash
SAVEIFS=$IFS
IFS="$(printf '\n\t')"
function extract {
if [ $# -eq 0 ]; then
# display usage if no parameters given
echo "Usage: extract <path/file_name>.<zip|rar|bz2|gz|tar|tbz2|tgz|Z|7z|xz|ex|tar.bz2|tar.gz|tar.xz|.zlib|.cso>"
echo " extract <path/file_name_1.ext> [path/file_name_2.ext] [path/file_name_3.ext]"
fi
for n in "$@"; do
if [ ! -f "$n" ]; then
echo "'$n' - file doesn't exist"
return 1
fi
case "''${n%,}" in
*.cbt | *.tar.bz2 | *.tar.gz | *.tar.xz | *.tbz2 | *.tgz | *.txz | *.tar)
tar zxvf "$n"
;;
*.lzma) unlzma ./"$n" ;;
*.bz2) bunzip2 ./"$n" ;;
*.cbr | *.rar) unrar x -ad ./"$n" ;;
*.gz) gunzip ./"$n" ;;
*.cbz | *.epub | *.zip) unzip ./"$n" ;;
*.z) uncompress ./"$n" ;;
*.7z | *.apk | *.arj | *.cab | *.cb7 | *.chm | *.deb | *.iso | *.lzh | *.msi | *.pkg | *.rpm | *.udf | *.wim | *.xar | *.vhd)
7z x ./"$n"
;;
*.xz) unxz ./"$n" ;;
*.exe) cabextract ./"$n" ;;
*.cpio) cpio -id <./"$n" ;;
*.cba | *.ace) unace x ./"$n" ;;
*.zpaq) zpaq x ./"$n" ;;
*.arc) arc e ./"$n" ;;
*.cso) ciso 0 ./"$n" ./"$n.iso" &&
extract "$n.iso" && \rm -f "$n" ;;
*.zlib) zlib-flate -uncompress <./"$n" >./"$n.tmp" &&
mv ./"$n.tmp" ./"''${n%.*zlib}" && rm -f "$n" ;;
*.dmg)
hdiutil mount ./"$n" -mountpoint "./$n.mounted"
;;
*)
echo "extract: '$n' - unknown archive method"
return 1
;;
esac
done
}
IFS=$SAVEIFS

View file

@ -0,0 +1,21 @@
#!/usr/bin/env bash
set -euo pipefail
OLD_TRANSID=$(sudo btrfs subvolume find-new /mnt/root-blank 9999999)
OLD_TRANSID=${OLD_TRANSID#transid marker was }
sudo btrfs subvolume find-new "/mnt/root" "$OLD_TRANSID" |
sed '$d' |
cut -f17- -d' ' |
sort |
uniq |
while read -r path; do
path="/$path"
if [ -L "$path" ]; then
: # The path is a symbolic link, so is probably handled by NixOS already
elif [ -d "$path" ]; then
: # The path is a directory, ignore
else
echo "$path"
fi
done

View file

@ -0,0 +1,20 @@
#!/usr/bin/env bash
case "$1" in
-*) exit 0 ;;
esac
case "$(file --mime-type "$1")" in
*text*)
bat --color always --plain "$1"
;;
*image* | *pdf)
catimg -w 100 -r 2 "$1"
;;
*directory*)
eza --icons -1 --color=always "$1"
;;
*)
echo "unknown file format"
;;
esac

View file

@ -0,0 +1,31 @@
#!/usr/bin/env bash
# find all .direnv directories
direnv_dirs=$(fd -I -a --hidden --type directory --glob '.direnv')
# check if any directories were found
if [ -z "$direnv_dirs" ]; then
echo "No .direnv directories found."
exit 0
fi
# print report
echo "The following .direnv directories will be deleted:"
echo "$direnv_dirs"
# confirm deletion
read -p "Are you sure you want to delete these directories? (y/n) " -n 1 -r
# move to a new line
echo -en "\n"
if [[ $REPLY =~ ^[Yy]$ ]]; then
# Delete directories
echo "Deleting directories..."
for dir in $direnv_dirs; do
rm -rf "$dir"
done
echo "Directories deleted."
else
echo "Operation cancelled."
fi

View file

@ -0,0 +1,4 @@
#!/usr/bin/env sh
# https://www.linkedin.com/pulse/how-identify-kill-zombiedefunct-processes-linux-without-george-gabra/
ps -A -ostat,ppid | grep -e '[zZ]' | awk '{ print $2 }' | uniq | xargs ps -p

View file

@ -0,0 +1,20 @@
#!/usr/bin/env bash
mkdir -p mods/
# Loop through each subdirectory in the current directory
for subdir in */; do
# Find the most recently accessed file with a .tmod extension in the subdirectory
latest_file=$(find "$subdir" -name "*.tmod" -type f -printf "%T@ %p\n" | sort -n | tail -1 | awk '{print $2}')
# Copy the latest file found (if any) to the mods/ directory
if [[ -n $latest_file ]]; then
cp "$latest_file" "mods/"
echo "Copied $latest_file to mods/"
else
echo "No .tmod files found in $subdir"
fi
done
# Zip up the mods/ directory
zip -r mods.zip mods/
echo -en "Zipped up mods/ directory to mods.zip"

View file

@ -0,0 +1,9 @@
{
imports = [
./bin
./zsh
./starship.nix
./bash.nix
];
}

View file

@ -0,0 +1,103 @@
{
config,
lib,
...
}: let
inherit (builtins) map;
inherit (lib.strings) concatStrings;
in {
home = {
sessionVariables = {
STARSHIP_CACHE = "${config.xdg.cacheHome}/starship";
};
};
programs.starship = let
elemsConcatted = concatStrings (
map (s: "\$${s}") [
"hostname"
"username"
"directory"
"shell"
"nix_shell"
"git_branch"
"git_commit"
"git_state"
"git_status"
"jobs"
"cmd_duration"
]
);
in {
enable = true;
settings = {
scan_timeout = 2;
command_timeout = 2000; # nixpkgs makes starship implode with lower values
add_newline = false;
line_break.disabled = false;
format = "${elemsConcatted}\n$character";
hostname = {
ssh_only = true;
disabled = false;
format = "@[$hostname](bold blue) "; # the whitespace at the end is actually important
};
# configure specific elements
character = {
error_symbol = "[](bold red)";
success_symbol = "[](bold green)";
vicmd_symbol = "[](bold yellow)";
format = "$symbol [|](bold bright-black) ";
};
username = {
format = "[$user]($style) in ";
};
directory = {
truncation_length = 2;
# removes the read_only symbol from the format, it doesn't play nicely with my folder icon
format = "[ ](bold green) [$path]($style) ";
# the following removes tildes from the path, and substitutes some folders with shorter names
substitutions = {
"~/Dev" = "Dev";
"~/Documents" = "Docs";
};
};
# git
git_commit.commit_hash_length = 7;
git_branch.style = "bold purple";
git_status = {
style = "red";
ahead = " ";
behind = " ";
conflicted = " ";
renamed = "»";
deleted = " ";
diverged = " ";
modified = "!";
stashed = "";
staged = "+";
untracked = "?";
};
# language configurations
# the whitespaces at the end *are* necessary for proper formatting
lua.symbol = "[ ](blue) ";
python.symbol = "[ ](blue) ";
rust.symbol = "[ ](red) ";
nix_shell.symbol = "[󱄅 ](blue) ";
golang.symbol = "[󰟓 ](blue)";
c.symbol = "[ ](black)";
nodejs.symbol = "[󰎙 ](yellow)";
package.symbol = "📦 ";
};
};
}

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