From f5508c747c0ee7786060d939a88d9b1d7769c695 Mon Sep 17 00:00:00 2001 From: Noah Masur <7386960+nmasur@users.noreply.github.com> Date: Sat, 30 Apr 2022 10:21:43 -0400 Subject: [PATCH] move fish functions into nix --- fish.configlink/functions/abbrs.fish | 152 ------------------ fish.configlink/functions/brews.fish | 10 -- fish.configlink/functions/brewsearch.fish | 9 -- .../functions/commandline-git-commits.fish | 14 +- fish.configlink/functions/copy.fish | 3 - fish.configlink/functions/edit.fish | 10 +- fish.configlink/functions/envs.fish | 3 - fish.configlink/functions/fcd.fish | 20 ++- .../functions/fish_user_key_bindings.fish | 30 ++-- .../functions/fzf_key_bindings.fish | 1 - .../functions/generate_fish_colors.fish | 8 - fish.configlink/functions/git-add-fuzzy.fish | 28 ++-- .../functions/git-checkout-fuzzy.fish | 4 - fish.configlink/functions/git-commits.fish | 18 +-- .../functions/git-delete-fuzzy.fish | 4 - .../functions/git-force-delete-fuzzy.fish | 4 - .../functions/git-fuzzy-branch.fish | 22 ++- fish.configlink/functions/git-history.fish | 28 ++-- .../functions/git-merge-fuzzy.fish | 4 - .../functions/git-push-upstream.fish | 10 +- fish.configlink/functions/git-show-fuzzy.fish | 14 +- fish.configlink/functions/git.fish | 66 ++++---- fish.configlink/functions/ip.fish | 10 +- fish.configlink/functions/journal.fish | 10 -- fish.configlink/functions/json.fish | 3 - fish.configlink/functions/linux.fish | 4 - fish.configlink/functions/ls.fish | 3 - fish.configlink/functions/meeting.fish | 11 -- fish.configlink/functions/note-dates.fish | 7 - fish.configlink/functions/note-header.fish | 4 - fish.configlink/functions/note.fish | 14 +- fish.configlink/functions/ping.fish | 3 - fish.configlink/functions/prj.fish | 5 - fish.configlink/functions/psf.fish | 3 - fish.configlink/functions/qr.fish | 3 - fish.configlink/functions/quicknote.fish | 5 - fish.configlink/functions/recent.fish | 10 +- fish.configlink/functions/reload.fish | 3 - fish.configlink/functions/repos.fish | 42 ----- fish.configlink/functions/syncnotes.fish | 16 +- fish.configlink/functions/theme_gruvbox.fish | 141 ---------------- fish.configlink/functions/tickers.fish | 11 -- fish.configlink/functions/today.fish | 11 -- fish.configlink/functions/uncommitted.fish | 25 ++- fish.configlink/functions/unsetaws.fish | 6 - fish.configlink/functions/up-or-search.fish | 29 ---- fish.configlink/functions/worldmap.fish | 3 - modules/desktop/i3.nix | 1 + modules/desktop/xorg.nix | 5 + modules/editor/neovim.nix | 7 + modules/shell/fish.nix | 72 +++++++-- modules/shell/git.nix | 70 +++++++- modules/shell/github.nix | 26 ++- modules/shell/utilities.nix | 29 +++- modules/system/doas.nix | 4 +- 55 files changed, 331 insertions(+), 727 deletions(-) delete mode 100644 fish.configlink/functions/abbrs.fish delete mode 100644 fish.configlink/functions/brews.fish delete mode 100644 fish.configlink/functions/brewsearch.fish delete mode 100644 fish.configlink/functions/copy.fish delete mode 100644 fish.configlink/functions/envs.fish delete mode 120000 fish.configlink/functions/fzf_key_bindings.fish delete mode 100644 fish.configlink/functions/generate_fish_colors.fish delete mode 100644 fish.configlink/functions/git-checkout-fuzzy.fish delete mode 100644 fish.configlink/functions/git-delete-fuzzy.fish delete mode 100644 fish.configlink/functions/git-force-delete-fuzzy.fish delete mode 100644 fish.configlink/functions/git-merge-fuzzy.fish delete mode 100644 fish.configlink/functions/journal.fish delete mode 100644 fish.configlink/functions/json.fish delete mode 100644 fish.configlink/functions/linux.fish delete mode 100644 fish.configlink/functions/ls.fish delete mode 100644 fish.configlink/functions/meeting.fish delete mode 100644 fish.configlink/functions/note-dates.fish delete mode 100644 fish.configlink/functions/note-header.fish delete mode 100644 fish.configlink/functions/ping.fish delete mode 100644 fish.configlink/functions/prj.fish delete mode 100644 fish.configlink/functions/psf.fish delete mode 100644 fish.configlink/functions/qr.fish delete mode 100644 fish.configlink/functions/quicknote.fish delete mode 100644 fish.configlink/functions/reload.fish delete mode 100755 fish.configlink/functions/repos.fish delete mode 100644 fish.configlink/functions/theme_gruvbox.fish delete mode 100644 fish.configlink/functions/tickers.fish delete mode 100644 fish.configlink/functions/today.fish mode change 100755 => 100644 fish.configlink/functions/uncommitted.fish delete mode 100644 fish.configlink/functions/unsetaws.fish delete mode 100644 fish.configlink/functions/up-or-search.fish delete mode 100644 fish.configlink/functions/worldmap.fish diff --git a/fish.configlink/functions/abbrs.fish b/fish.configlink/functions/abbrs.fish deleted file mode 100644 index 1dc7f97..0000000 --- a/fish.configlink/functions/abbrs.fish +++ /dev/null @@ -1,152 +0,0 @@ -#!/usr/local/bin/fish - -function abbrs --description 'All abbreviations' - - # Directory aliases - abbr -a l ls - abbr -a lh 'ls -lh' - abbr -a ll 'ls -alhF' - abbr -a lf 'ls -lh | fzf' - abbr -a c cd - abbr -a -- - 'cd -' - abbr -a proj 'cd $PROJ' - abbr -a mkd 'mkdir -pv' - - # Tmux - abbr -a ta 'tmux attach-session' - abbr -a tan 'tmux attach-session -t noah' - abbr -a tnn 'tmux new-session -s noah' - - # Git - abbr -a g git - abbr -a gs 'git status' - abbr -a gd 'git diff' - abbr -a gds 'git diff --staged' - abbr -a gdp 'git diff HEAD^' - abbr -a ga 'git add' - abbr -a gaa 'git add -A' - abbr -a gac 'git commit -am' - abbr -a gc 'git commit -m' - abbr -a gca 'git commit --amend --no-edit' - abbr -a gcae 'git commit --amend' - abbr -a gu 'git pull' - abbr -a gp 'git push' - abbr -a gpp git-push-upstream - abbr -a gl 'git log --graph --decorate --oneline -20' - abbr -a gll 'git log --graph --decorate --oneline' - abbr -a gco 'git checkout' - abbr -a gcom 'git checkout master' - abbr -a gcob 'git checkout -b' - abbr -a gb 'git branch' - abbr -a gbd 'git branch -d' - abbr -a gbD 'git branch -D' - abbr -a gr 'git reset' - abbr -a grh 'git reset --hard' - abbr -a gm 'git merge' - abbr -a gcp 'git cherry-pick' - abbr -a cdg 'cd (git rev-parse --show-toplevel)' - - # GitHub - abbr -a ghr 'gh repo view -w' - abbr -a gha 'gh run list | head -1 | awk \'{ print $(NF-2) }\' | xargs gh run view' - abbr -a grw 'noti gh run watch' - abbr -a grf 'gh run view --log-failed' - abbr -a grl 'gh run view --log' - abbr -a ghpr 'gh pr create && sleep 3 && noti gh run watch' - abbr -a ghm 'gh pr merge -s -d && git pull' - - # Vim - if command -v nvim >/dev/null - alias --save vim='nvim' - abbr -a vimrc 'vim $HOME/.config/nvim/init.lua' - else - alias --save vim='vim' - abbr -a vimrc 'vim $HOME/.vimrc' - end - abbr -a v vim - abbr -a vl 'vim -c "normal! `0"' - abbr -a vll 'vim -c "Telescope oldfiles"' - abbr -a vh 'vim -c "Telescope oldfiles"' - - # Notes - abbr -a qn quicknote - abbr -a sn syncnotes - abbr -a to today - abbr -a work 'vim $NOTES_PATH/work.md' - - # RSS - abbr -a nb newsboat - - # Improved CLI Tools - abbr -a cat bat # Swap cat with bat - abbr -a h 'http -Fh --all' # Curl site for headers - abbr -a j just - abbr -a scim sc-im - - # Fun CLI Tools - abbr weather 'curl wttr.in/$WEATHER_CITY' - abbr moon 'curl wttr.in/Moon' - - # Dotfile and config shortcuts - abbr -a s sudo - abbr -a boot '$DOTS/scripts/bootstrap' - abbr -a sshc 'vim ~/.ssh/config' - abbr -a hosts 'sudo nvim /etc/hosts' - abbr -a frc 'vim $HOME/.config/fish/config.fish' - abbr -a falias 'vim $HOME/.config/fish/functions/abbrs.fish' - - # Cheat Sheets - abbr -a ssl 'openssl req -new -newkey rsa:2048 -nodes' \ - '-keyout server.key -out server.csr' - abbr -a fingerprint 'ssh-keyscan myhost.com | ssh-keygen -lf -' - abbr -a publickey 'ssh-keygen -y -f ~/.ssh/id_rsa > ~/.ssh/id_rsa.pub' - abbr -a forloop 'for i in (seq 1 100)' - abbr -a gatekeeper 'sudo spctl --master-disable' - abbr -a flushdns 'sudo dscacheutil -flushcache && sudo killall -HUP mDNSResponder' - - # Docker - abbr -a dc '$DOTS/bin/docker_cleanup' - abbr -a dr 'docker run --rm -it' - abbr -a db 'docker build . -t' - abbr -a ds 'docker ps -a' - abbr -a de 'docker exec -it' - abbr -a dpy 'docker run --rm -it -v $PWD:/project python:alpine python' - abbr -a alp 'docker run --rm -it -v $PWD:/project alpine sh' - - # Terraform - abbr -a te terraform - abbr -a tap 'terraform apply' - - # Kubernetes - abbr -a k kubectl - abbr -a pods 'kubectl get pods -A' - abbr -a nodes 'kubectl get nodes' - abbr -a deploys 'kubectl get deployments -A' - abbr -a dash kube-dashboard - abbr -a ks k9s - - # Cloud - abbr -a awsc 'vim ~/.aws/credentials' - - # Python - abbr -a py python - abbr -a po poetry - abbr -a pr 'poetry run python' - abbr -a pl 'poetry run pylint *' - abbr -a black 'poetry run black --target-version py38 .' - abbr -a bl 'poetry run black --target-version py38 .' - - # Rust - abbr -a ca cargo - - # macOS - abbr -a casks 'vim $DOTS/homebrew/Caskfile' - abbr -a t trash - - # Linux - if [ (uname) = Linux ] - linux - end - - -end diff --git a/fish.configlink/functions/brews.fish b/fish.configlink/functions/brews.fish deleted file mode 100644 index f1d573a..0000000 --- a/fish.configlink/functions/brews.fish +++ /dev/null @@ -1,10 +0,0 @@ -function brews --description "Open Homebrew bundles file" - set -lx brewdir $DOTS/homebrew - set -l brewfile (basename $brewdir/*.Brewfile \ - | fzf \ - --height 70% \ - --preview-window right:70% \ - --preview 'bat --color=always $brewdir/{}' \ - ) - and vim $brewdir/$brewfile -end diff --git a/fish.configlink/functions/brewsearch.fish b/fish.configlink/functions/brewsearch.fish deleted file mode 100644 index c716297..0000000 --- a/fish.configlink/functions/brewsearch.fish +++ /dev/null @@ -1,9 +0,0 @@ -function brewsearch --description "Install brew plugins" - set -l inst (brew formulae | eval "fzf $FZF_DEFAULT_OPTS -m --header='[press ctrl-i for info, enter to install]' --bind 'ctrl-i:preview(brew info {})'") - - if not test (count $inst) = 0 - for prog in $inst - brew install "$prog" - end - end -end diff --git a/fish.configlink/functions/commandline-git-commits.fish b/fish.configlink/functions/commandline-git-commits.fish index e579742..f883560 100644 --- a/fish.configlink/functions/commandline-git-commits.fish +++ b/fish.configlink/functions/commandline-git-commits.fish @@ -1,10 +1,6 @@ -#!/usr/local/bin/fish - -function commandline-git-commits - set commit (git-commits) - if [ $commit ] - commandline -i "$commit" - else - commandline -i "HEAD" - end +set commit (git-commits) +if [ $commit ] + commandline -i "$commit" +else + commandline -i HEAD end diff --git a/fish.configlink/functions/copy.fish b/fish.configlink/functions/copy.fish deleted file mode 100644 index 0f8f037..0000000 --- a/fish.configlink/functions/copy.fish +++ /dev/null @@ -1,3 +0,0 @@ -function copy --description 'Copy file contents into clipboard' - cat $argv | pbcopy -end diff --git a/fish.configlink/functions/edit.fish b/fish.configlink/functions/edit.fish index f86daee..fbe13b0 100644 --- a/fish.configlink/functions/edit.fish +++ b/fish.configlink/functions/edit.fish @@ -1,6 +1,4 @@ -function edit --description "Open a file in Vim" - set vimfile (fzf) - and set vimfile (echo $vimfile | tr -d '\r') - and commandline -r "vim $vimfile" - and commandline -f execute -end +set vimfile (fzf) +and set vimfile (echo $vimfile | tr -d '\r') +and commandline -r "vim $vimfile" +and commandline -f execute diff --git a/fish.configlink/functions/envs.fish b/fish.configlink/functions/envs.fish deleted file mode 100644 index d5b6e79..0000000 --- a/fish.configlink/functions/envs.fish +++ /dev/null @@ -1,3 +0,0 @@ -function envs --description 'Set from a bash environment variables file' - set -gx (cat $argv | tr "=" " " | string split ' ') -end diff --git a/fish.configlink/functions/fcd.fish b/fish.configlink/functions/fcd.fish index a99d734..dd48ff9 100644 --- a/fish.configlink/functions/fcd.fish +++ b/fish.configlink/functions/fcd.fish @@ -1,12 +1,10 @@ -function fcd --description 'Jump to directory' -a 'directory' - if test -z $directory - set directory "$HOME" - end - if ! test -d $directory - echo "Directory not found: $directory" - return 1 - end - set jump (fd -t d . $directory | fzf) - and cd $jump $argv; - and commandline -f execute; +if test -z $directory + set directory "$HOME" end +if ! test -d $directory + echo "Directory not found: $directory" + return 1 +end +set jump (fd -t d . $directory | fzf) +and cd $jump $argv +and commandline -f execute diff --git a/fish.configlink/functions/fish_user_key_bindings.fish b/fish.configlink/functions/fish_user_key_bindings.fish index 78d73ee..7a08fbb 100644 --- a/fish.configlink/functions/fish_user_key_bindings.fish +++ b/fish.configlink/functions/fish_user_key_bindings.fish @@ -1,17 +1,13 @@ -#!/usr/local/bin/fish - -function fish_user_key_bindings - bind -M insert \co 'edit' - bind -M default \co 'edit' - bind -M insert \ca 'cd ~; and edit; and commandline -a "; cd -"; commandline -f execute' - bind -M default \ca 'cd ~; and edit; and commandline -a "; cd -"; commandline -f execute' - bind -M insert \ce 'recent' - bind -M default \ce 'recent' - bind -M insert \cg 'commandline-git-commits' - bind -M insert \cf 'fcd' - bind -M default \cf 'fcd' - bind -M insert \cp 'prj' - bind -M default \cp 'prj' - bind -M insert \x1F accept-autosuggestion - bind -M default \x1F accept-autosuggestion -end +bind -M insert \co edit +bind -M default \co edit +bind -M insert \ca 'cd ~; and edit; and commandline -a "; cd -"; commandline -f execute' +bind -M default \ca 'cd ~; and edit; and commandline -a "; cd -"; commandline -f execute' +bind -M insert \ce recent +bind -M default \ce recent +bind -M insert \cg commandline-git-commits +bind -M insert \cf fcd +bind -M default \cf fcd +bind -M insert \cp projects +bind -M default \cp projects +bind -M insert \x1F accept-autosuggestion +bind -M default \x1F accept-autosuggestion diff --git a/fish.configlink/functions/fzf_key_bindings.fish b/fish.configlink/functions/fzf_key_bindings.fish deleted file mode 120000 index a66a998..0000000 --- a/fish.configlink/functions/fzf_key_bindings.fish +++ /dev/null @@ -1 +0,0 @@ -/usr/local/opt/fzf/shell/key-bindings.fish \ No newline at end of file diff --git a/fish.configlink/functions/generate_fish_colors.fish b/fish.configlink/functions/generate_fish_colors.fish deleted file mode 100644 index f6f2581..0000000 --- a/fish.configlink/functions/generate_fish_colors.fish +++ /dev/null @@ -1,8 +0,0 @@ -# This function creates an output file of just the printf values for -# modifying the shell colors. This output file is used to load the -# current colors into my shell much faster than running the function on -# prompt. - -function generate_fish_colors --description "Create fish colors file" - theme_gruvbox dark > $DOTS/fish.configlink/fish_colors -end diff --git a/fish.configlink/functions/git-add-fuzzy.fish b/fish.configlink/functions/git-add-fuzzy.fish index ac2b8d5..9e9f641 100644 --- a/fish.configlink/functions/git-add-fuzzy.fish +++ b/fish.configlink/functions/git-add-fuzzy.fish @@ -1,16 +1,14 @@ -function git-add-fuzzy - set gitfile (git status -s \ - | fzf \ - --height 50% \ - -m \ - --preview-window right:70% \ - --layout reverse \ - --preview 'set -l IFS; set gd (git diff --color=always (echo {} | awk \'{$1=$1};1\' | cut -d" " -f2)); if test "$gd"; echo "$gd"; else; bat --color=always (echo {} | awk \'{$1=$1};1\' | cut -d" " -f2); end') - and for gf in $gitfile - set gf (echo $gf \ - | awk '{$1=$1};1' \ - | cut -d' ' -f2 \ - ) - and git add $gf - end +set gitfile (git status -s \ + | fzf \ + --height 50% \ + -m \ + --preview-window right:70% \ + --layout reverse \ + --preview 'set -l IFS; set gd (git diff --color=always (echo {} | awk \'{$1=$1};1\' | cut -d" " -f2)); if test "$gd"; echo "$gd"; else; bat --color=always (echo {} | awk \'{$1=$1};1\' | cut -d" " -f2); end') +and for gf in $gitfile + set gf (echo $gf \ + | awk '{$1=$1};1' \ + | cut -d' ' -f2 \ + ) + and git add $gf end diff --git a/fish.configlink/functions/git-checkout-fuzzy.fish b/fish.configlink/functions/git-checkout-fuzzy.fish deleted file mode 100644 index 1b47663..0000000 --- a/fish.configlink/functions/git-checkout-fuzzy.fish +++ /dev/null @@ -1,4 +0,0 @@ -function git-checkout-fuzzy - set branch (git-fuzzy-branch "checkout branch...") - and git checkout $branch -end diff --git a/fish.configlink/functions/git-commits.fish b/fish.configlink/functions/git-commits.fish index 03c3613..ce2b7fd 100644 --- a/fish.configlink/functions/git-commits.fish +++ b/fish.configlink/functions/git-commits.fish @@ -1,10 +1,8 @@ -function git-commits - set commitline (git log \ - --pretty="format:%C(auto)%ar %h%d %s" \ - | fzf \ - --height 50% \ - --preview 'git show --color=always (echo {} | cut -d" " -f4)' \ - ) - and set commit (echo $commitline | cut -d" " -f4) - and echo $commit -end +set commitline (git log \ + --pretty="format:%C(auto)%ar %h%d %s" \ + | fzf \ + --height 50% \ + --preview 'git show --color=always (echo {} | cut -d" " -f4)' \ + ) +and set commit (echo $commitline | cut -d" " -f4) +and echo $commit diff --git a/fish.configlink/functions/git-delete-fuzzy.fish b/fish.configlink/functions/git-delete-fuzzy.fish deleted file mode 100644 index 82cd5e7..0000000 --- a/fish.configlink/functions/git-delete-fuzzy.fish +++ /dev/null @@ -1,4 +0,0 @@ -function git-delete-fuzzy - set branch (git-fuzzy-branch "delete branch...") - and git branch -d $branch -end diff --git a/fish.configlink/functions/git-force-delete-fuzzy.fish b/fish.configlink/functions/git-force-delete-fuzzy.fish deleted file mode 100644 index 119b5f0..0000000 --- a/fish.configlink/functions/git-force-delete-fuzzy.fish +++ /dev/null @@ -1,4 +0,0 @@ -function git-force-delete-fuzzy - set branch (git-fuzzy-branch "force delete branch...") - and git branch -D $branch -end diff --git a/fish.configlink/functions/git-fuzzy-branch.fish b/fish.configlink/functions/git-fuzzy-branch.fish index f60acaf..374b992 100644 --- a/fish.configlink/functions/git-fuzzy-branch.fish +++ b/fish.configlink/functions/git-fuzzy-branch.fish @@ -1,12 +1,10 @@ -function git-fuzzy-branch -a header - set -l current (git rev-parse --abbrev-ref HEAD | tr -d '\n') - set -l branch (git branch \ - --format "%(refname:short)" \ - | fzf \ - --height 50% \ - --header="On $current, $header" \ - --preview-window right:70% \ - --preview 'git log {} --color=always --pretty="format:%C(auto)%ar %h%d %s"' \ - ) - and echo $branch -end +set -l current (git rev-parse --abbrev-ref HEAD | tr -d '\n') +set -l branch (git branch \ + --format "%(refname:short)" \ + | fzf \ + --height 50% \ + --header="On $current, $header" \ + --preview-window right:70% \ + --preview 'git log {} --color=always --pretty="format:%C(auto)%ar %h%d %s"' \ + ) +and echo $branch diff --git a/fish.configlink/functions/git-history.fish b/fish.configlink/functions/git-history.fish index 1865a54..fc7e252 100644 --- a/fish.configlink/functions/git-history.fish +++ b/fish.configlink/functions/git-history.fish @@ -1,16 +1,14 @@ -function git-history - if not count $argv > /dev/null - echo "Must provide filename." - return 1 - end - set commitline ( git log \ - --follow \ - --pretty="format:%C(auto)%ar %h%d %s" \ - -- ./$argv \ - | fzf \ - --height 100% \ - --preview "git diff --color=always (echo {} | cut -d' ' -f4)^1..(echo {} | cut -d' ' -f4) -- ./$argv" \ - ) - and set commit (echo $commitline | cut -d" " -f4) - and echo $commit +if not count $argv >/dev/null + echo "Must provide filename." + return 1 end +set commitline ( git log \ + --follow \ + --pretty="format:%C(auto)%ar %h%d %s" \ + -- ./$argv \ + | fzf \ + --height 100% \ + --preview "git diff --color=always (echo {} | cut -d' ' -f4)^1..(echo {} | cut -d' ' -f4) -- ./$argv" \ + ) +and set commit (echo $commitline | cut -d" " -f4) +and echo $commit diff --git a/fish.configlink/functions/git-merge-fuzzy.fish b/fish.configlink/functions/git-merge-fuzzy.fish deleted file mode 100644 index 82fb7e9..0000000 --- a/fish.configlink/functions/git-merge-fuzzy.fish +++ /dev/null @@ -1,4 +0,0 @@ -function git-merge-fuzzy - set branch (git-fuzzy-branch "merge from...") - and git merge $branch -end diff --git a/fish.configlink/functions/git-push-upstream.fish b/fish.configlink/functions/git-push-upstream.fish index 06c8250..82e82fd 100644 --- a/fish.configlink/functions/git-push-upstream.fish +++ b/fish.configlink/functions/git-push-upstream.fish @@ -1,6 +1,4 @@ -function git-push-upstream --description "Create upstream branch" - set -l branch (git branch 2>/dev/null | grep '^\*' | colrm 1 2) - set -l command "git push --set-upstream origin $branch" - commandline -r $command - commandline -f execute -end +set -l branch (git branch 2>/dev/null | grep '^\*' | colrm 1 2) +set -l command "git push --set-upstream origin $branch" +commandline -r $command +commandline -f execute diff --git a/fish.configlink/functions/git-show-fuzzy.fish b/fish.configlink/functions/git-show-fuzzy.fish index 0e6cbaa..44da9f9 100644 --- a/fish.configlink/functions/git-show-fuzzy.fish +++ b/fish.configlink/functions/git-show-fuzzy.fish @@ -1,8 +1,6 @@ -function git-show-fuzzy - set commitline (git log \ - --pretty="format:%C(auto)%ar %h%d %s" \ - | fzf \ - ) - and set commit (echo $commitline | cut -d" " -f4 ) - and git show $commit -end +set commitline (git log \ + --pretty="format:%C(auto)%ar %h%d %s" \ + | fzf \ + ) +and set commit (echo $commitline | cut -d" " -f4 ) +and git show $commit diff --git a/fish.configlink/functions/git.fish b/fish.configlink/functions/git.fish index 19e1b73..be63ae0 100644 --- a/fish.configlink/functions/git.fish +++ b/fish.configlink/functions/git.fish @@ -1,39 +1,37 @@ -function git - if contains f $argv - switch $argv[1] - case "checkout" - git-checkout-fuzzy - case "add" - git-add-fuzzy - case "show" - git-show-fuzzy - case "merge" - git-merge-fuzzy - case "branch" - if test "$argv[2]" = "-d" - git-delete-fuzzy - else if test "$argv[2]" = "-D" - git-force-delete-fuzzy - else - echo "Not a fuzzy option." - return 1 - end - case "reset" - set commit (git-commits) - and if test "$argv[2]" = "--hard" - git reset --hard $commit - else - git reset $commit - end - case "*" - echo "No fuzzy option." +if contains f $argv + switch $argv[1] + case checkout + git-checkout-fuzzy + case add + git-add-fuzzy + case show + git-show-fuzzy + case merge + git-merge-fuzzy + case branch + if test "$argv[2]" = -d + git-delete-fuzzy + else if test "$argv[2]" = -D + git-force-delete-fuzzy + else + echo "Not a fuzzy option." return 1 end + case reset + set commit (git-commits) + and if test "$argv[2]" = --hard + git reset --hard $commit + else + git reset $commit + end + case "*" + echo "No fuzzy option." + return 1 + end +else + if count $argv >/dev/null + command git $argv else - if count $argv > /dev/null - command git $argv - else - command git status -sb - end + command git status -sb end end diff --git a/fish.configlink/functions/ip.fish b/fish.configlink/functions/ip.fish index 2da35a7..1808915 100644 --- a/fish.configlink/functions/ip.fish +++ b/fish.configlink/functions/ip.fish @@ -1,7 +1,5 @@ -function ip - if count $argv > /dev/null - curl ipinfo.io/$argv - else - curl checkip.amazonaws.com - end +if count $argv >/dev/null + curl ipinfo.io/$argv +else + curl checkip.amazonaws.com end diff --git a/fish.configlink/functions/journal.fish b/fish.configlink/functions/journal.fish deleted file mode 100644 index c5a94c6..0000000 --- a/fish.configlink/functions/journal.fish +++ /dev/null @@ -1,10 +0,0 @@ -function journal --description "Create today's journal" - note-dates - if [ -f $TODAY_NOTE_FILE ] - echo "Already exists." - else - note-header - printf $JOURNAL_HEADER > $TODAY_NOTE_FILE - echo "New journal added." - end -end diff --git a/fish.configlink/functions/json.fish b/fish.configlink/functions/json.fish deleted file mode 100644 index 89643db..0000000 --- a/fish.configlink/functions/json.fish +++ /dev/null @@ -1,3 +0,0 @@ -function json --description "Tidy up JSON with jq" - pbpaste | jq '.' | pbcopy -end diff --git a/fish.configlink/functions/linux.fish b/fish.configlink/functions/linux.fish deleted file mode 100644 index b5fe2ef..0000000 --- a/fish.configlink/functions/linux.fish +++ /dev/null @@ -1,4 +0,0 @@ -function linux --description "Load only on Linux" - alias pbcopy='xclip -selection clipboard -in' - alias pbpaste='xclip -selection clipboard -out' -end diff --git a/fish.configlink/functions/ls.fish b/fish.configlink/functions/ls.fish deleted file mode 100644 index 6eeff32..0000000 --- a/fish.configlink/functions/ls.fish +++ /dev/null @@ -1,3 +0,0 @@ -function ls --description "Use exa to list files" - exa $argv -end diff --git a/fish.configlink/functions/meeting.fish b/fish.configlink/functions/meeting.fish deleted file mode 100644 index 98f1f1d..0000000 --- a/fish.configlink/functions/meeting.fish +++ /dev/null @@ -1,11 +0,0 @@ -function meeting --description "Describe a meeting" -a "name" - note-dates - set today_date (date -j +"%Y-%m-%d") - set time (date +"%I:%M%p" | tr '[:upper:]' '[:lower:]') - set meeting_name (echo $name | tr ' ' '-' | tr '[:upper:]' '[:lower:]') - set meeting_note $today_date-$meeting_name - set meeting_file meetings/$meeting_note.md - printf "[$TODAY_NOTE](../journal/$TODAY_NOTE.md) | #meeting\n\n# $name\n\n---\n\n" > $NOTES_PATH/$meeting_file - printf "\n\n---\n\n$time - [$name](../$meeting_file)\n\n---\n\n" >> $TODAY_NOTE_FILE - vim $NOTES_PATH/$meeting_file -end diff --git a/fish.configlink/functions/note-dates.fish b/fish.configlink/functions/note-dates.fish deleted file mode 100644 index f4e4c6b..0000000 --- a/fish.configlink/functions/note-dates.fish +++ /dev/null @@ -1,7 +0,0 @@ -function note-dates - set -g TODAY_NOTE (date +"%Y-%m-%d_%a") - set -g YESTERDAY_NOTE (date -jv "-1d" +"%Y-%m-%d_%a") - set -g TOMORROW_NOTE (date -jv "+1d" +"%Y-%m-%d_%a") - set -g LONG_DATE (date +"%A, %B %e, %Y" | sed 's/ */ /g') - set -g TODAY_NOTE_FILE $NOTES_PATH/journal/$TODAY_NOTE.md -end diff --git a/fish.configlink/functions/note-header.fish b/fish.configlink/functions/note-header.fish deleted file mode 100644 index 6dd8408..0000000 --- a/fish.configlink/functions/note-header.fish +++ /dev/null @@ -1,4 +0,0 @@ -function note-header - set -g CURRENT_WEATHER (curl -s "https://wttr.in/?format=1") - set -g JOURNAL_HEADER "[Yesterday]($YESTERDAY_NOTE.md) | [Home](../home.md) | [Today](obsidian://advanced-uri?daily=true) | [Tomorrow]($TOMORROW_NOTE.md)\n\n$LONG_DATE\n$CURRENT_WEATHER\n#journal\n\n---\n\n" -end diff --git a/fish.configlink/functions/note.fish b/fish.configlink/functions/note.fish index 42df0f4..58d1e29 100644 --- a/fish.configlink/functions/note.fish +++ b/fish.configlink/functions/note.fish @@ -1,10 +1,8 @@ -function note --description "Edit or create a note" -a "filename" - if test -n "$filename" - vim $NOTES_PATH/$filename.md - else - set file (ls $NOTES_PATH | fzf) - if [ $status -eq 0 ] - vim $NOTES_PATH/$file - end +if test -n "$filename" + vim $NOTES_PATH/$filename.md +else + set file (ls $NOTES_PATH | fzf) + if [ $status -eq 0 ] + vim $NOTES_PATH/$file end end diff --git a/fish.configlink/functions/ping.fish b/fish.configlink/functions/ping.fish deleted file mode 100644 index 730e2c2..0000000 --- a/fish.configlink/functions/ping.fish +++ /dev/null @@ -1,3 +0,0 @@ -function ping --description "Improved ping" -a "target" - prettyping --nolegend $target -end diff --git a/fish.configlink/functions/prj.fish b/fish.configlink/functions/prj.fish deleted file mode 100644 index a19bb37..0000000 --- a/fish.configlink/functions/prj.fish +++ /dev/null @@ -1,5 +0,0 @@ -function prj --description "cd to a project" - set projdir (ls $PROJ | fzf) - and cd $PROJ/$projdir - and commandline -f execute -end diff --git a/fish.configlink/functions/psf.fish b/fish.configlink/functions/psf.fish deleted file mode 100644 index 95c1f2c..0000000 --- a/fish.configlink/functions/psf.fish +++ /dev/null @@ -1,3 +0,0 @@ -function psf --description "Search for open process" -a "process" - ps aux | rg -v "$USER.*rg $argv" | rg $argv -end diff --git a/fish.configlink/functions/qr.fish b/fish.configlink/functions/qr.fish deleted file mode 100644 index e84946f..0000000 --- a/fish.configlink/functions/qr.fish +++ /dev/null @@ -1,3 +0,0 @@ -function qr - qrencode $argv[1] -o /tmp/qr.png | open /tmp/qr.png -end diff --git a/fish.configlink/functions/quicknote.fish b/fish.configlink/functions/quicknote.fish deleted file mode 100644 index 40a955d..0000000 --- a/fish.configlink/functions/quicknote.fish +++ /dev/null @@ -1,5 +0,0 @@ -function quicknote --description "Write a quick note" -a "note" - note-dates - set time (date +"%I:%M%p" | tr '[:upper:]' '[:lower:]') - printf "\n\n---\n\n#### $time\n$note\n" >> $TODAY_NOTE_FILE -end diff --git a/fish.configlink/functions/recent.fish b/fish.configlink/functions/recent.fish index b717f88..d3d1c40 100644 --- a/fish.configlink/functions/recent.fish +++ b/fish.configlink/functions/recent.fish @@ -1,6 +1,4 @@ -function recent --description "Open a recent file in Vim" - set vimfile (fd -t f --exec stat -f "%m%t%N" | sort -nr | cut -f2 | fzf) - and set vimfile (echo $vimfile | tr -d '\r') - and commandline -r "vim $vimfile" - and commandline -f execute -end +set vimfile (fd -t f --exec stat -f "%m%t%N" | sort -nr | cut -f2 | fzf) +and set vimfile (echo $vimfile | tr -d '\r') +and commandline -r "vim $vimfile" +and commandline -f execute diff --git a/fish.configlink/functions/reload.fish b/fish.configlink/functions/reload.fish deleted file mode 100644 index 736e594..0000000 --- a/fish.configlink/functions/reload.fish +++ /dev/null @@ -1,3 +0,0 @@ -function reload --description "Reload fish configuration" - source $DOTS/fish.configlink/config.fish -end diff --git a/fish.configlink/functions/repos.fish b/fish.configlink/functions/repos.fish deleted file mode 100755 index f1d9b3e..0000000 --- a/fish.configlink/functions/repos.fish +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/local/bin/fish - -function repos --description 'Clone GitHub repositories' -a 'organization' - set directory (gh-repos $organization) - and cd $directory -end - #switch $organization - # case t2; set organization "take-two" - # case d2c; set organization "take-two-t2gp" - # case t2gp; set organization "take-two-t2gp" - # case pd; set organization "private-division" - # case dots; set organization "playdots" - # case '*'; set organization "nmasur" - #end - - #set selected (gh repo list "$organization" \ - # --limit 50 \ - # --no-archived \ - # --json=name,description,isPrivate,updatedAt,primaryLanguage \ - # | jq -r '.[] | .name + "," + if .description == "" then "-" else .description end + "," + .updatedAt + "," + .primaryLanguage.name' \ - # | begin - # echo "REPO,DESCRIPTION,UPDATED,LANGUAGE" - # cat - - # end | column -s , -t - # | fzf \ - # --header-lines=1 \ - # --layout=reverse - #--bind "ctrl-o:execute:gh repo view -w $organization/{1}" \ - #--preview "GH_FORCE_TTY=49% gh repo view $organization/{1} | glow -" \ - #--preview-window up -#) - #if test -n (echo $selected | tr -d '\r') - # set directory "$HOME/dev/work" - # if test $organization = "nmasur" - # set directory "$HOME/dev/personal" - # end - # set repo (echo $selected | awk '{print $1}') - # set repo_full "$organization/$repo" - # gh repo clone "$repo_full" "$directory/$repo" - # cd "$directory/$repo" - #end -#end diff --git a/fish.configlink/functions/syncnotes.fish b/fish.configlink/functions/syncnotes.fish index 98924cb..70ce739 100644 --- a/fish.configlink/functions/syncnotes.fish +++ b/fish.configlink/functions/syncnotes.fish @@ -1,9 +1,7 @@ -function syncnotes --description "Full git commit on notes" - set current_dir $PWD - cd $NOTES_PATH - git pull - git add -A - git commit -m "autosync" - git push - cd $current_dir -end +set current_dir $PWD +cd $NOTES_PATH +git pull +git add -A +git commit -m autosync +git push +cd $current_dir diff --git a/fish.configlink/functions/theme_gruvbox.fish b/fish.configlink/functions/theme_gruvbox.fish deleted file mode 100644 index 58a3cf2..0000000 --- a/fish.configlink/functions/theme_gruvbox.fish +++ /dev/null @@ -1,141 +0,0 @@ -#!/usr/bin/fish -function theme_gruvbox --description 'Apply gruvbox theme' - set -l mode 'light' - if test (count $argv) -gt 0 - set mode $argv[1] - end - - set -g contrast 'medium' - if test (count $argv) -gt 1 - set contrast $argv[2] - end - - switch $contrast - case 'soft' - case 'medium' - case 'hard' - case '*' - set_color $fish_color_error - echo 'Unknown contrast $contrast, choose soft, medium or hard' - set_color $fish_color_normal - return 1 - end - - switch $mode - case 'light' - __theme_gruvbox_base - __theme_gruvbox_light - case 'dark' - __theme_gruvbox_base - __theme_gruvbox_dark - case '*' - set_color $fish_color_error - echo 'Unknown mode $mode, choose light or dark' - set_color $fish_color_normal - return 1 - end - __theme_gruvbox_palette - return 0 -end - -function __theme_gruvbox_base - __printf_color 1 'cc/24/1d' - __printf_color 2 '98/97/1a' - __printf_color 3 'd7/99/21' - __printf_color 4 '45/85/88' - __printf_color 5 'b1/62/86' - __printf_color 6 '68/9d/6a' -end - -function __theme_gruvbox_light - set -l bg 'fb/f1/c7' - switch $contrast - case "soft" - set bg 'f2/e5/bc' - case "hard" - set bg 'f9/f5/d7' - end - command printf "\033]11;rgb:$bg\007" - - set -l fg '3c/38/36' - command printf "\033]10;rgb:$fg\007" - - __printf_color 0 $bg - __printf_color 7 '7c/6f/64' - __printf_color 8 '92/83/74' - __printf_color 9 '9d/00/06' - __printf_color 10 '79/74/0e' - __printf_color 11 'b5/76/14' - __printf_color 12 '07/66/78' - __printf_color 13 '8f/3f/71' - __printf_color 14 '42/7b/58' - __printf_color 15 $fg -end - -function __theme_gruvbox_dark - set -l bg '28/28/28' - switch $contrast - case "soft" - set bg '32/30/2f' - case "hard" - set bg '1d/20/21' - end - command printf "\033]11;rgb:$bg\007" - - set -l fg 'eb/db/b2' - command printf "\033]10;rgb:$fg\007" - - __printf_color 0 $bg - __printf_color 7 'a8/99/84' - __printf_color 8 '92/83/74' - __printf_color 9 'fb/59/34' - __printf_color 10 'b8/bb/26' - __printf_color 11 'fa/bd/2f' - __printf_color 12 '83/a5/98' - __printf_color 13 'd3/86/9b' - __printf_color 14 '8e/c0/7c' - __printf_color 15 $fg -end - -function __theme_gruvbox_palette - __printf_color 236 '32/30/2f' - __printf_color 234 '1d/20/21' - - __printf_color 235 '28/28/28' - __printf_color 237 '3c/38/36' - __printf_color 239 '50/49/45' - __printf_color 241 '66/5c/54' - __printf_color 243 '7c/6f/64' - - __printf_color 244 '92/83/74' - __printf_color 245 '92/83/74' - - __printf_color 228 'f2/e5/bc' - __printf_color 230 'f9/f5/d7' - - __printf_color 229 'fb/f1/c7' - __printf_color 223 'eb/db/b2' - __printf_color 250 'd5/c4/a1' - __printf_color 248 'bd/ae/93' - __printf_color 246 'a8/99/84' - - __printf_color 167 'fb/49/34' - __printf_color 142 'b8/bb/26' - __printf_color 214 'fa/bd/2f' - __printf_color 109 '83/a5/98' - __printf_color 175 'd3/86/9b' - __printf_color 108 '8e/c0/7c' - __printf_color 208 'fe/80/19' - - __printf_color 88 '9d/00/06' - __printf_color 100 '79/74/0e' - __printf_color 136 'b5/76/14' - __printf_color 24 '07/66/78' - __printf_color 96 '8f/3f/71' - __printf_color 66 '42/7b/58' - __printf_color 130 'af/3a/03' -end - -function __printf_color - command printf "\033]4;$argv[1];rgb:$argv[2]\007" -end diff --git a/fish.configlink/functions/tickers.fish b/fish.configlink/functions/tickers.fish deleted file mode 100644 index 34d6d36..0000000 --- a/fish.configlink/functions/tickers.fish +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/local/bin/fish - -function tickers --description "Stock and money tickers" - abbr -a tk 'tickrs -s' - abbr -a vt 'tickrs -s vt' - abbr -a vti 'tickrs -s vti' - abbr -a vxus 'tickrs -s vxus' - abbr -a btc 'rates btc usd' - abbr -a ada 'rates ada usd' - abbr -a eth 'rates eth usd' -end diff --git a/fish.configlink/functions/today.fish b/fish.configlink/functions/today.fish deleted file mode 100644 index 5f5c411..0000000 --- a/fish.configlink/functions/today.fish +++ /dev/null @@ -1,11 +0,0 @@ -function today --description "Open today's journal" - note-dates - if [ -f $TODAY_NOTE_FILE ] - vim $TODAY_NOTE_FILE - else - note-header - printf $JOURNAL_HEADER > $TODAY_NOTE_FILE - echo "New journal added." - vim $TODAY_NOTE_FILE - end -end diff --git a/fish.configlink/functions/uncommitted.fish b/fish.configlink/functions/uncommitted.fish old mode 100755 new mode 100644 index 824adc6..4e4fcc9 --- a/fish.configlink/functions/uncommitted.fish +++ b/fish.configlink/functions/uncommitted.fish @@ -1,16 +1,11 @@ -#!/usr/local/bin/fish - -function uncommitted --description "Find uncommitted git repos" - set current_dir (pwd) - cd $HOME/dev - find . -type d -name '.git' | \ - while read dir - cd $dir/../ - and if test -n (echo (git status -s)) - pwd - git status -s - end - cd - - end - cd $current_dir +set current_dir (pwd) +cd $HOME/dev +find . -type d -name '.git' | while read dir + cd $dir/../ + and if test -n (echo (git status -s)) + pwd + git status -s + end + cd - end +cd $current_dir diff --git a/fish.configlink/functions/unsetaws.fish b/fish.configlink/functions/unsetaws.fish deleted file mode 100644 index 6d6ad47..0000000 --- a/fish.configlink/functions/unsetaws.fish +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/local/fish - -function unsetaws --description "Clear AWS credentials environment variables" - set -e AWS_ACCESS_KEY_ID - set -e AWS_SECRET_ACCESS_KEY -end diff --git a/fish.configlink/functions/up-or-search.fish b/fish.configlink/functions/up-or-search.fish deleted file mode 100644 index 502c8ce..0000000 --- a/fish.configlink/functions/up-or-search.fish +++ /dev/null @@ -1,29 +0,0 @@ -# by @farcaller from https://github.com/fish-shell/fish-shell/issues/825#issuecomment-440286038 - -function up-or-search -d "Depending on cursor position and current mode, either search backward or move up one line" - # If we are already in search mode, continue - if commandline --search-mode - commandline -f history-search-backward - return - end - - # If we are navigating the pager, then up always navigates - if commandline --paging-mode - commandline -f up-line - return - end - - # We are not already in search mode. - # If we are on the top line, start search mode, - # otherwise move up - set lineno (commandline -L) - - switch $lineno - case 1 - commandline -f history-search-backward - history merge # <-- ADDED THIS - - case '*' - commandline -f up-line - end -end diff --git a/fish.configlink/functions/worldmap.fish b/fish.configlink/functions/worldmap.fish deleted file mode 100644 index 8778b08..0000000 --- a/fish.configlink/functions/worldmap.fish +++ /dev/null @@ -1,3 +0,0 @@ -function worldmap --description "Terminal atlas" - telnet mapscii.me -end diff --git a/modules/desktop/i3.nix b/modules/desktop/i3.nix index 2cae778..aee7be0 100644 --- a/modules/desktop/i3.nix +++ b/modules/desktop/i3.nix @@ -227,6 +227,7 @@ window = { border = 1; hideEdgeBorders = "both"; + titlebar = false; }; workspaceAutoBackAndForth = false; workspaceOutputAssign = [ ]; diff --git a/modules/desktop/xorg.nix b/modules/desktop/xorg.nix index 62f0843..ef3cd09 100644 --- a/modules/desktop/xorg.nix +++ b/modules/desktop/xorg.nix @@ -25,5 +25,10 @@ xclip # Clipboard ]; + home-manager.users.${user}.programs.fish.shellAliases = { + pbcopy = "xclip -selection clipboard -in"; + pbpaste = "xclip -selection clipboard -out"; + }; + } diff --git a/modules/editor/neovim.nix b/modules/editor/neovim.nix index 43d344d..89b85af 100644 --- a/modules/editor/neovim.nix +++ b/modules/editor/neovim.nix @@ -13,6 +13,13 @@ programs.git.extraConfig.core.editor = "nvim"; home.sessionVariables = { EDITOR = "nvim"; }; + programs.fish = { + shellAliases = { vim = "nvim"; }; + shellAbbrs = { + vll = "vim -c 'Telescope oldfiles'"; + vimrc = "vim ${builtins.toString ../../.}/nvim.configlink/init.lua"; + }; + }; }; diff --git a/modules/shell/fish.nix b/modules/shell/fish.nix index 99d05b7..565baef 100644 --- a/modules/shell/fish.nix +++ b/modules/shell/fish.nix @@ -3,15 +3,69 @@ users.users.${user}.shell = pkgs.fish; home-manager.users.${user} = { + home.packages = with pkgs; [ fzf exa fd bat ripgrep ]; programs.fish = { enable = true; - functions = { }; + functions = { + commandline-git-commits = { + description = "Insert commit into commandline"; + body = builtins.readFile + ../../fish.configlink/functions/commandline-git-commits.fish; + }; + copy = { + description = "Copy file contents into clipboard"; + body = "cat $argv | pbcopy"; # Need to fix for non-macOS + }; + edit = { + description = "Open a file in Vim"; + body = builtins.readFile ../../fish.configlink/functions/edit.fish; + }; + envs = { + description = "Evaluate a bash-like environment variables file"; + body = ''set -gx (cat $argv | tr "=" " " | string split ' ')''; + }; + fcd = { + description = "Jump to directory"; + argumentNames = "directory"; + body = builtins.readFile ../../fish.configlink/functions/fcd.fish; + }; + fish_user_key_bindings = { + body = builtins.readFile + ../../fish.configlink/functions/fish_user_key_bindings.fish; + }; + ip = { + body = builtins.readFile ../../fish.configlink/functions/ip.fish; + }; + json = { + description = "Tidy up JSON using jq"; + body = "pbpaste | jq '.' | pbcopy"; # Need to fix for non-macOS + }; + note = { + description = "Edit or create a note"; + argumentNames = "filename"; + body = builtins.readFile ../../fish.configlink/functions/note.fish; + }; + projects = { + description = "Jump to a project"; + body = '' + set projdir (ls $PROJ | fzf) + and cd $PROJ/$projdir + and commandline -f execute + ''; + }; + recent = { + description = "Open a recent file in Vim"; + body = builtins.readFile ../../fish.configlink/functions/recent.fish; + }; + syncnotes = { + description = "Full git commit on notes"; + body = + builtins.readFile ../../fish.configlink/functions/syncnotes.fish; + }; + }; interactiveShellInit = ""; loginShellInit = ""; - shellAliases = { - vim = "nvim"; - sudo = "doas"; - }; + shellAliases = { ls = "exa"; }; shellAbbrs = { # Directory aliases @@ -40,17 +94,11 @@ # Vim v = "vim"; vl = "vim -c 'normal! `0'"; - vll = "vim -c 'Telescope oldfiles'"; - vimrc = "vim ${builtins.toString ../../.}/nvim.configlink/init.lua"; # Notes - qn = "quicknote"; sn = "syncnotes"; - to = "today"; - work = "vim $NOTES_PATH/work.md"; # CLI Tools - cat = "bat"; # Swap cat with bat h = "http -Fh --all"; # Curl site for headers m = "make"; # For makefiles @@ -90,7 +138,6 @@ ca = "cargo"; }; - shellAliases = { }; shellInit = ""; }; @@ -113,7 +160,6 @@ xdg.configFile = { "starship.toml".source = ../../starship/starship.toml.configlink; - "fish/functions".source = ../../fish.configlink/functions; }; programs.direnv = { diff --git a/modules/shell/git.nix b/modules/shell/git.nix index 9677362..f837ce5 100644 --- a/modules/shell/git.nix +++ b/modules/shell/git.nix @@ -1,4 +1,8 @@ -{ pkgs, user, fullName, ... }: { +{ config, pkgs, lib, user, fullName, ... }: + +let home-packages = config.home-manager.users.${user}.home.packages; + +in { home-manager.users.${user} = { programs.git = { @@ -25,7 +29,7 @@ gcae = "git commit --amend"; gu = "git pull"; gp = "git push"; - gpp = "git_set_upstream"; + gpp = "git-push-upstream"; gl = "git log --graph --decorate --oneline -20"; gll = "git log --graph --decorate --oneline"; gco = "git checkout"; @@ -40,6 +44,68 @@ gcp = "git cherry-pick"; cdg = "cd (git rev-parse --show-toplevel)"; }; + + programs.fish.functions = lib.mkIf (builtins.elem pkgs.fzf home-packages + && builtins.elem pkgs.bat home-packages) { + git = { + body = builtins.readFile ../../fish.configlink/functions/git.fish; + }; + git-add-fuzzy = { + body = builtins.readFile + ../../fish.configlink/functions/git-add-fuzzy.fish; + }; + git-fuzzy-branch = { + argumentNames = "header"; + body = builtins.readFile + ../../fish.configlink/functions/git-fuzzy-branch.fish; + }; + git-checkout-fuzzy = { + body = '' + set branch (git-fuzzy-branch "checkout branch...") + and git checkout $branch + ''; + }; + git-delete-fuzzy = { + body = '' + set branch (git-fuzzy-branch "delete branch...") + and git branch -d $branch + ''; + }; + git-force-delete-fuzzy = { + body = '' + set branch (git-fuzzy-branch "force delete branch...") + and git branch -D $branch + ''; + }; + git-merge-fuzzy = { + body = '' + set branch (git-fuzzy-branch "merge from...") + and git merge $branch + ''; + }; + git-show-fuzzy = { + body = builtins.readFile + ../../fish.configlink/functions/git-show-fuzzy.fish; + }; + git-commits = { + body = + builtins.readFile ../../fish.configlink/functions/git-commits.fish; + }; + git-history = { + body = + builtins.readFile ../../fish.configlink/functions/git-history.fish; + }; + git-push-upstream = { + description = "Create upstream branch"; + body = builtins.readFile + ../../fish.configlink/functions/git-push-upstream.fish; + }; + uncommitted = { + description = "Find uncommitted git repos"; + body = + builtins.readFile ../../fish.configlink/functions/uncommitted.fish; + }; + }; }; } diff --git a/modules/shell/github.nix b/modules/shell/github.nix index 733ddab..0673e25 100644 --- a/modules/shell/github.nix +++ b/modules/shell/github.nix @@ -9,13 +9,25 @@ settings.git_protocol = "https"; }; - programs.fish.shellAbbrs = { - ghr = "gh repo view -w"; - gha = - "gh run list | head -1 | awk '{ print $(NF-2) }' | xargs gh run view"; - grw = "gh run watch"; - grf = "gh run view --log-failed"; - grl = "gh run view --log"; + programs.fish = { + shellAbbrs = { + ghr = "gh repo view -w"; + gha = + "gh run list | head -1 | awk '{ print $(NF-2) }' | xargs gh run view"; + grw = "gh run watch"; + grf = "gh run view --log-failed"; + grl = "gh run view --log"; + }; + functions = { + repos = { + description = "Clone GitHub repositories"; + argumentNames = "organization"; + body = '' + set directory (gh-repos $organization) + and cd $directory + ''; + }; + }; }; }; diff --git a/modules/shell/utilities.nix b/modules/shell/utilities.nix index c9ee525..ada3e5b 100644 --- a/modules/shell/utilities.nix +++ b/modules/shell/utilities.nix @@ -13,32 +13,45 @@ let in { - home-manager.users.${user}.home = { + home-manager.users.${user} = { - packages = with pkgs; [ + home.packages = with pkgs; [ unzip rsync - fzf ripgrep bat fd - exa sd - zoxide jq tealdeer - gh - direnv tree htop glow + prettyping + qrencode ]; - file = { + home.file = { ".rgignore".text = ignorePatterns; ".fdignore".text = ignorePatterns; }; + programs.fish.shellAbbrs = { + cat = "bat"; # Swap cat with bat + }; + + programs.fish.functions = { + ping = { + description = "Improved ping"; + argumentNames = "target"; + body = "prettyping --nolegend $target"; + }; + qr = { + body = + "qrencode $argv[1] -o /tmp/qr.png | open /tmp/qr.png"; # Fix for non-macOS + }; + }; + }; } diff --git a/modules/system/doas.nix b/modules/system/doas.nix index b6d7eef..cc4a63f 100644 --- a/modules/system/doas.nix +++ b/modules/system/doas.nix @@ -1,6 +1,6 @@ # Replace sudo with doas -{ ... }: { +{ user, ... }: { security = { @@ -23,4 +23,6 @@ }]; }; }; + + home-manager.users.${user}.programs.fish.shellAliases = { sudo = "doas"; }; }