speed up fish start with individual function files

This commit is contained in:
Noah Masur 2020-12-17 19:29:55 -07:00
parent 1c79530fb1
commit ec64f2a0f4
31 changed files with 225 additions and 257 deletions

View File

@ -8,6 +8,8 @@ if status --is-interactive
set PATH $PATH /usr/local/bin ~/.local/bin $DOTS/bin ~/.cargo/bin
set CDPATH . $HOME
set EDITOR nvim
set PROJ $HOME/dev/work
set NOTES_PATH $HOME/notes
# Use `vi` in the shell with cursor shapes
fish_vi_key_bindings
@ -33,11 +35,6 @@ if status --is-interactive
# Individual features
aliases
notes
awstools
mactools
gittools
projects
# Fuzzy finder
fzf_key_bindings

View File

@ -8,6 +8,8 @@ function aliases --description 'All aliases'
abbr -a lh 'ls -lh' # Pretty vertical list
abbr -a ll 'ls -alhF' # Include hidden files
abbr -a c 'cd'
abbr -a .. 'cd ..'
alias proj='cd $PROJ'
# Tmux
abbr -a ta 'tmux attach-session'
@ -36,6 +38,7 @@ function aliases --description 'All aliases'
abbr -a gbD 'git branch -D'
abbr -a gr 'git reset'
abbr -a grh 'git reset --hard'
abbr -a grm 'git reset --mixed'
abbr -a gm 'git merge'
abbr -a gmf 'git-merge-fuzzy'
abbr -a gcp 'git cherry-pick'
@ -48,6 +51,10 @@ function aliases --description 'All aliases'
abbr -a vimrc 'vim $HOME/.config/nvim/init.vim' # Edit ".vimrc" file
end
# Notes
abbr -a qn 'quicknote'
abbr -a sn 'syncnotes'
# Improved CLI Tools
alias ping='prettyping --nolegend'
abbr -a cat 'bat' # Swap cat with bat
@ -121,7 +128,10 @@ function aliases --description 'All aliases'
# Rust
abbr -a ca 'cargo'
# Non-MacOS
# macOS
abbr -a casks 'vim $DOTS/homebrew/Caskfile'
# Non-macOS
if [ (uname) = "Linux" ]
alias pbcopy='xclip -selection clipboard -in'
alias pbpaste='xclip -selection clipboard -out'

View File

@ -1,8 +0,0 @@
#!/usr/bin/local/fish
function awstools --description "AWS bindings"
function unsetaws --description "Clear AWS credentials environment variables"
set -e AWS_ACCESS_KEY_ID
set -e AWS_SECRET_ACCESS_KEY
end
end

View File

@ -0,0 +1,9 @@
function brewinfo --description "Lookup brew plugins"
set -l inst (brew search | eval "fzf $FZF_DEFAULT_OPTS -m --header='[brew:info]'")
if not test (count $inst) = 0
for prog in $inst
brew info "$prog"
end
end
end

View File

@ -0,0 +1,10 @@
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

View File

@ -0,0 +1,9 @@
function brewsearch --description "Install brew plugins"
set -l inst (brew search | eval "fzf $FZF_DEFAULT_OPTS -m --header='[brew:install]'")
if not test (count $inst) = 0
for prog in $inst
brew install "$prog"
end
end
end

View File

@ -0,0 +1,3 @@
function copy --description 'Copy file contents into clipboard'
cat $argv | pbcopy
end

View File

@ -0,0 +1,9 @@
function fuck -d "Correct your previous console command"
set -l fucked_up_command $history[1]
env TF_SHELL=fish TF_ALIAS=fuck PYTHONIOENCODING=utf-8 thefuck $fucked_up_command THEFUCK_ARGUMENT_PLACEHOLDER $argv | read -l unfucked_command
if [ "$unfucked_command" != "" ]
eval $unfucked_command
builtin history delete --exact --case-sensitive -- $fucked_up_command
builtin history merge ^ /dev/null
end
end

View File

@ -0,0 +1,15 @@
function git-add-fuzzy
set gitfile (git status -s \
| fzf \
--height 50% \
-m \
--preview-window right:70% \
--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
end

View File

@ -0,0 +1,4 @@
function git-checkout-fuzzy
set branch (git-fuzzy-branch "checkout branch...")
and git checkout $branch
end

View File

@ -0,0 +1,10 @@
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

View File

@ -0,0 +1,4 @@
function git-delete-fuzzy
set branch (git-fuzzy-branch "delete branch...")
and git branch -d $branch
end

View File

@ -0,0 +1,4 @@
function git-force-delete-fuzzy
set branch (git-fuzzy-branch "force delete branch...")
and git branch -D $branch
end

View File

@ -0,0 +1,12 @@
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

View File

@ -0,0 +1,4 @@
function git-merge-fuzzy
set branch (git-fuzzy-branch "merge from...")
and git merge $branch
end

View File

@ -0,0 +1,4 @@
function git-show-fuzzy
set commit (git log --pretty=oneline | fzf | cut -d' ' -f1)
and git show $commit
end

View File

@ -0,0 +1,39 @@
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."
return 1
end
else
if count $argv > /dev/null
command git $argv
else
command git status -sb
end
end
end

View File

@ -1,110 +0,0 @@
#!/usr/local/bin/fish
function gittools
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
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
function git-checkout-fuzzy
set branch (git-fuzzy-branch "checkout branch...")
and git checkout $branch
end
function git-show-fuzzy
set commit (git log --pretty=oneline | fzf | cut -d' ' -f1)
and git show $commit
end
function git-add-fuzzy
set gitfile (git status -s \
| fzf \
--height 50% \
-m \
--preview-window right:70% \
--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
end
function git-merge-fuzzy
set branch (git-fuzzy-branch "merge from...")
and git merge $branch
end
function git-delete-fuzzy
set branch (git-fuzzy-branch "delete branch...")
and git branch -d $branch
end
function git-force-delete-fuzzy
set branch (git-fuzzy-branch "force delete branch...")
and git branch -D $branch
end
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."
return 1
end
else
if count $argv > /dev/null
command git $argv
else
command git status -sb
end
end
end
end

View File

@ -0,0 +1,10 @@
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

View File

@ -1,42 +0,0 @@
#!/usr/local/bin/fish
function mactools
function copy --description 'Copy file contents into clipboard'
cat $argv | pbcopy
end
abbr -a casks 'vim $DOTS/homebrew/Caskfile'
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
function brewinfo --description "Lookup brew plugins"
set -l inst (brew search | eval "fzf $FZF_DEFAULT_OPTS -m --header='[brew:info]'")
if not test (count $inst) = 0
for prog in $inst
brew info "$prog"
end
end
end
function brewsearch --description "Install brew plugins"
set -l inst (brew search | eval "fzf $FZF_DEFAULT_OPTS -m --header='[brew:install]'")
if not test (count $inst) = 0
for prog in $inst
brew install "$prog"
end
end
end
end

View File

@ -0,0 +1,10 @@
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
printf "[$TODAY_NOTE](journal/$TODAY_NOTE.md) | #meeting\n\n# $name\n\n---\n\n" > $NOTES_PATH/$meeting_note.md
printf "\n\n---\n\n$time - [$name](../$meeting_note.md)\n\n---\n\n" >> $TODAY_NOTE_FILE
open "obsidian://open?vault=notes&file=$meeting_note"
end

View File

@ -0,0 +1,7 @@
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

View File

@ -0,0 +1,4 @@
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) | [Tomorrow]($TOMORROW_NOTE.md)\n\n$LONG_DATE\n$CURRENT_WEATHER\n#journal\n\n---\n\n# Today's Goals\n\n\n# Journal\n\n"
end

View File

@ -0,0 +1,10 @@
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
end
end

View File

@ -1,83 +1,5 @@
#!/usr/local/bin/fish
function notes --description "Notes functions"
set -gx NOTES_PATH $HOME/notes
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
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) | [Tomorrow]($TOMORROW_NOTE.md)\n\n$LONG_DATE\n$CURRENT_WEATHER\n#journal\n\n---\n\n# Today's Goals\n\n\n# Journal\n\n"
end
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
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
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
printf "[$TODAY_NOTE](journal/$TODAY_NOTE.md) | #meeting\n\n# $name\n\n---\n\n" > $NOTES_PATH/$meeting_note.md
printf "\n\n---\n\n$time - [$name](../$meeting_note.md)\n\n---\n\n" >> $TODAY_NOTE_FILE
open "obsidian://open?vault=notes&file=$meeting_note"
end
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
end
end
abbr -a qn 'quicknote'
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
abbr -a sn 'syncnotes'
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
end

View File

@ -0,0 +1,4 @@
function prj --description "cd to a project"
set projdir (ls $PROJ | fzf)
and cd $PROJ/$projdir
end

View File

@ -1,13 +0,0 @@
#!/usr/bin/local/fish
function projects --description "Projects tools"
set PROJ $HOME/dev/work
alias proj='cd $PROJ'
function prj --description "cd to a project"
set projdir (ls $PROJ | fzf)
and cd $PROJ/$projdir
end
end

View File

@ -0,0 +1,5 @@
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

View File

@ -0,0 +1,9 @@
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

View File

@ -0,0 +1,11 @@
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

View File

@ -0,0 +1,6 @@
#!/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