diff --git a/modules/home/core/home.nix b/modules/home/core/home.nix index d40f7cc5..c6c9bb8c 100644 --- a/modules/home/core/home.nix +++ b/modules/home/core/home.nix @@ -42,6 +42,7 @@ delta docker-compose eza + fd feh fx fzf @@ -133,7 +134,7 @@ yarn zed-editor zellij - zoxide + # zoxide ]; }; } diff --git a/modules/home/opt/shell/fish/default.nix b/modules/home/opt/shell/fish/default.nix index 2f6072a3..19940eed 100644 --- a/modules/home/opt/shell/fish/default.nix +++ b/modules/home/opt/shell/fish/default.nix @@ -1,6 +1,11 @@ -{ pkgs, ... }: +{ lib, pkgs, ... }: { + xdg.configFile."fish/functions" = { + source = lib.cleanSourceWith { src = lib.cleanSource ./functions/.; }; + recursive = true; + }; + programs.fish = { enable = true; functions = { @@ -28,6 +33,18 @@ inherit (pkgs.fishPlugins.sponge) src; name = "sponge"; } + { + inherit (pkgs.fishPlugins.z) src; + name = "z"; + } + # { + # inherit (pkgs.fishPlugins.fzf) src; + # name = "fzf"; + # } + { + inherit (pkgs.fishPlugins.fzf-fish) src; + name = "fzf-fish"; + } ]; }; } diff --git a/modules/home/opt/shell/fish/functions/bak.fish b/modules/home/opt/shell/fish/functions/bak.fish new file mode 100644 index 00000000..47c56aa6 --- /dev/null +++ b/modules/home/opt/shell/fish/functions/bak.fish @@ -0,0 +1,24 @@ +function bak + if [ (count $argv) -ne 1 ] + echo "1 path must be supplied" + return 1 + end + set file (basename $argv[1] '.bak') + set other "$file.bak" + if test -e $argv[1] + if test -e $other + mv $argv[1] $other.tmp + mv $other $argv[1] + mv $other.tmp $other + else + mv $argv[1] $other + end + else + if test -e $other + mv $other $argv[1] + else + echo "Neither $argv[1] nor $other exist" + return 1 + end + end +end diff --git a/modules/home/opt/shell/fish/functions/cd.fish b/modules/home/opt/shell/fish/functions/cd.fish new file mode 100644 index 00000000..1ccc63a0 --- /dev/null +++ b/modules/home/opt/shell/fish/functions/cd.fish @@ -0,0 +1,32 @@ +function cd --description 'change directory and run onefetch if a git directory' + set -l parent + + # navigate to root of git repo + if [ $argv = ":/" ] + set -l top (command git rev-parse --show-cdup) + builtin cd $top + # check if cd to file and route to parent + else if [ -f $argv ] && [ -e $argv ] + set parent (dirname $argv) + if [ "$parent" != . ] && [ -d "$parent" ] + builtin cd "$parent" + end + # if navigating to a directory, cd as usual + else if [ -d $argv ] + if test -n "$argv" && + builtin cd "$argv" + else + builtin cd + end + end + + # check for git information + git rev-parse 2>/dev/null + + if test $status -eq 0 + if test -z "$LAST_REPO" -o "$LAST_REPO" != $(basename $(git rev-parse --show-toplevel)) + onefetch + set -g LAST_REPO $(basename $(git rev-parse --show-toplevel)) + end + end +end diff --git a/modules/home/opt/shell/fish/functions/ex.fish b/modules/home/opt/shell/fish/functions/ex.fish new file mode 100644 index 00000000..d5433baa --- /dev/null +++ b/modules/home/opt/shell/fish/functions/ex.fish @@ -0,0 +1,38 @@ +function ex + if test -f $argv[1] + set filename (basename $argv[1]) + set foldername (echo $filename | sed 's/\.[^.]*$//') + mkdir -p $foldername + switch $argv[1] + case '*.tar.bz2' + tar xjf $argv[1] -C $foldername + case '*.tar.gz' + tar xzf $argv[1] -C $foldername + case '*.bz2' + bunzip2 -k $argv[1] + mv (basename $argv[1] .bz2) ./$foldername/ + case '*.rar' + unrar x $argv[1] ./$foldername/ + case '*.gz' + gunzip -k $argv[1] + mv (basename $argv[1] .gz) ./$foldername/ + case '*.tar' + tar xf $argv[1] -C ./$foldername/ + case '*.tbz2' + tar xjf $argv[1] -C ./$foldername/ + case '*.tgz' + tar xzf $argv[1] -C ./$foldername/ + case '*.zip' + unzip -d ./$foldername/ "$filename" + case '*.Z' + uncompress "$filename" + mv (basename "$filename" ".Z") "./$foldername/" + case '*.7z' + 7z x "$filename" "-o./$foldername/" + otherwise + echo "'$filename' cannot be extracted via ex()" + end + else + echo "'$filename' is not a valid file" + end +end diff --git a/modules/home/opt/shell/fish/functions/git.fish b/modules/home/opt/shell/fish/functions/git.fish new file mode 100644 index 00000000..f329115a --- /dev/null +++ b/modules/home/opt/shell/fish/functions/git.fish @@ -0,0 +1,49 @@ +# Add custom git extensions +function git + set -l code + + # Truncate long lines in git grep + if test "$argv[1]" = grep + + if ! command -v perl &>/dev/null + command git $argv + return + end + + command git -c color.ui=always $argv | perl -pe 'my $truncate = 500; (my $blank = $_) =~ s/\e\[[^m]*m//g; if (length $blank > $truncate) { + s/^((?:(?:\e\[[^m]*m)+(?:.|$)|.(?:\e\[[^m]*m)*|$(*SKIP)(*FAIL)){$truncate})(?=(?:(?:\e\[[^m]*m)+(?:.|$)|.(?:\e\[[^m]*m)*|$(*SKIP)(*FAIL)){15}).*/$1\e\[m...(truncated)/ + }' + + return + end + + # Prevent accidental git commit -a + if test "$argv[1]" = commit && contains -- "$argv[2]" -a + if ! command git diff-index --cached --quiet HEAD -- && ! command git diff-files --quiet + + echo >&2 '\e[0;31mERROR!\e[0m Changes are already staged. Preventing git commit -a' + echo >&2 '\e[0;31mERROR!\e[0m Run git commit without -a or run git reset HEAD first' + + return 1 + end + end + + # forward original git command + if test -n "$argv" + command git $argv + else + command git + end + + # record command exit code + set code $status + + # output commit length if successful + if test "$argv[1]" = commit && ! code + printf 'Commit subject length: ' + command git log -1 --format="%s" | tr -d '\n' | wc -m | awk '{print $1}' + end + + # return original exit code + return $code +end diff --git a/modules/home/opt/shell/fish/functions/load_ssh.fish b/modules/home/opt/shell/fish/functions/load_ssh.fish new file mode 100644 index 00000000..ec16c07e --- /dev/null +++ b/modules/home/opt/shell/fish/functions/load_ssh.fish @@ -0,0 +1,9 @@ +function load_ssh + if status is-login + and status is-interactive + # To add a key, set -Ua SSH_KEYS_TO_AUTOLOAD keypath + # To remove a key, set -U --erase SSH_KEYS_TO_AUTOLOAD[index_of_key] + set -Ua SSH_KEYS_TO_AUTOLOAD ~/.ssh/id_rsa + keychain -q -Q --eval $SSH_KEYS_TO_AUTOLOAD | source + end +end diff --git a/modules/home/opt/shell/fish/functions/mkcd.fish b/modules/home/opt/shell/fish/functions/mkcd.fish new file mode 100644 index 00000000..9bf9ff2d --- /dev/null +++ b/modules/home/opt/shell/fish/functions/mkcd.fish @@ -0,0 +1,4 @@ +function mkcd + mkdir -p $argv + cd $argv +end diff --git a/modules/home/opt/shell/fish/functions/mvcd.fish b/modules/home/opt/shell/fish/functions/mvcd.fish new file mode 100644 index 00000000..336d4473 --- /dev/null +++ b/modules/home/opt/shell/fish/functions/mvcd.fish @@ -0,0 +1,7 @@ +function mvcd -d "Moves files and directories and changes the current directory" + if test (count $argv) -gt 1 + mkdir -p $argv[2] + mv $argv[1] $argv[2] + cd $argv[2] + end +end diff --git a/modules/home/opt/shell/fish/functions/nixify.fish b/modules/home/opt/shell/fish/functions/nixify.fish new file mode 100644 index 00000000..5e515ed5 --- /dev/null +++ b/modules/home/opt/shell/fish/functions/nixify.fish @@ -0,0 +1,16 @@ +function nixify + if not test -e ./.envrc + echo "use nix" >.envrc + direnv allow + end + if not test -e shell.nix -a ! -e default.nix + set code 'with import {}; + mkShell { + nativeBuildInputs = [ + bashInteractive + ]; + }' + echo $code | sed "s/'/'\\\\''/g" | xargs echo >default.nix + eval (env $EDITOR "default.nix") + end +end diff --git a/modules/home/opt/shell/zsh/default.nix b/modules/home/opt/shell/zsh/default.nix index 61fe9573..5f33fde1 100644 --- a/modules/home/opt/shell/zsh/default.nix +++ b/modules/home/opt/shell/zsh/default.nix @@ -22,7 +22,7 @@ ''; }; programs.atuin = { - enable = true; + enable = false; enableZshIntegration = true; settings = { style = "compact";