Remove private_ prefix from fish dir's

This commit is contained in:
2019-04-26 06:41:04 -04:00
parent de1dc7bab8
commit e6eb1bedd0
41 changed files with 5 additions and 4 deletions

View File

@@ -0,0 +1,208 @@
# copy this into ~/.config/fish/completions/ to enable autocomplete for the watson time tracker
function __fish_watson_needs_sub -d "provides a list of sub commands"
set cmd (commandline -opc)
if [ (count $cmd) -eq 1 -a $cmd[1] = 'watson' ]
return 0
end
return 1
end
function __fish_watson_using_command -d "determine if watson is using the passed command"
set cmd (commandline -opc)
if [ (count $cmd) -ge 2 -a $cmd[1] = 'watson' ]
if [ $argv[1] = $cmd[2] ]
return 0
end
return 1
end
return 1
end
function __fish_watson_set_cache_vars -d "set vars used for caches"
if test -n "$WATSON_DIR"
set -g _watson_dir $WATSON_DIR
else
# TODO: set dir for Darwin (not sure how to do regex in fish) #
set -g _watson_dir "$HOME/.config/watson"
end
set -g _watson_frame_file "$_watson_dir/frames"
set -g _watson_projects_cache "$_watson_dir/projects_cache"
set -g _watson_tags_cache "$_watson_dir/tags_cache"
set -g _watson_frames_cache "$_watson_dir/frames_cache"
end
function __get_date_num -d "return last modified time of file"
date -r $argv[1] +%s
end
function __fish_watson_check_if_refresh_cache -d "see if cache file needs refreshing"
if begin not test -e $argv[1];
or test (__get_date_num $_watson_frame_file) \
-gt (__get_date_num $argv[1]); end
return 1
else
return 0
end
end
function __fish_watson_get_projects -d "return a list of projects"
__fish_watson_set_cache_vars
__fish_watson_check_if_refresh_cache $_watson_projects_cache
# if test $status -eq 1
# command watson projects | tee $_watson_projects_cache
# else
# cat $_watson_projects_cache
# end
cat $_watson_projects_cache
end
function __fish_watson_get_tags -d "return a list of tags"
__fish_watson_set_cache_vars
__fish_watson_check_if_refresh_cache $_watson_tags_cache
# if test $status -eq 1
# command watson tags | tee $_watson_tags_cache
# else
# cat $_watson_tags_cache
# end
cat $_watson_tags_cache
end
function __fish_watson_get_frames -d "return a list of frames" #TODO, use watson logs to get more info
__fish_watson_set_cache_vars
__fish_watson_check_if_refresh_cache $_watson_frames_cache
if test $status -eq 1
command watson frames | tee $_watson_frames_cache
else
cat $_watson_frames_cache
end
end
function __fish_watson_has_project -d "determine if watson is using a passed command and if it has a project"
set cmd (commandline -opc)
if [ (count $cmd) -gt 2 -a $cmd[1] = 'watson' ]
if [ $argv[1] = $cmd[2] ]
if contains "$cmd[3]" (__fish_watson_get_projects)
return 0
end
end
end
return 1
end
function __fish_watson_has_from -d "determine if watson is using a passed command and if it is using from"
set cmd (commandline -opc)
if [ (count $cmd) -gt 2 -a $cmd[1] = 'watson' ]
if [ $argv[1] = $cmd[2] ]
if contains -- "$cmd[3]" -f --from
return 0
end
end
end
return 1
end
function __fish_watson_needs_project -d "check if we need a project"
set cmd (commandline -opc)
if [ (count $cmd) -ge 2 -a $cmd[1] = 'watson' ]
if [ $argv[1] = $cmd[2] ]
for i in $cmd
if contains $i (__fish_watson_get_projects)
return 1 # return 1 because we alredy have a project
end
end
return 0 # we are using $argv as our command and the command does not contain any projects
end
end
return 1
end
# if a backend.url is set, use it in the command description
if [ -e ~/.config/watson/config ]
set url_string (command watson config backend.url 2> /dev/null)
if test -n "$url_string"
set url $url_string
end
else
set url "a remote Crick server"
end
# ungrouped
complete -f -c watson -n '__fish_watson_needs_sub' -a cancel -d "Cancel the last start command"
complete -f -c watson -n '__fish_watson_needs_sub' -a stop -d " Stop monitoring time for the current project"
complete -f -c watson -n '__fish_watson_needs_sub' -a frames -d "Display the list of all frame IDs"
complete -f -c watson -n '__fish_watson_needs_sub' -a help -d "Display help information"
complete -f -c watson -n '__fish_watson_needs_sub' -a projects -d "Display the list of projects"
complete -f -c watson -n '__fish_watson_needs_sub' -a tags -d "Display the list of tags"
complete -f -c watson -n '__fish_watson_needs_sub' -a sync -d "sync your work with $url"
# config
complete -f -c watson -n '__fish_watson_needs_sub' -a config -d "Get and set configuration options"
complete -f -c watson -n '__fish_watson_using_command config' -s e -l edit -d "Edit the config with an editor"
# edit
complete -f -c watson -n '__fish_watson_needs_sub' -a edit -d "Edit a frame"
complete -f -c watson -n '__fish_watson_using_command edit' -a "(__fish_watson_get_frames)"
# log
complete -f -c watson -n '__fish_watson_needs_sub' -a log -d "Display sessions during the given timespan"
complete -f -c watson -n '__fish_watson_using_command log' -s c -l current -d "include the running frame"
complete -f -c watson -n '__fish_watson_using_command log' -s C -l no-current -d "exclude the running frame (default)"
complete -f -c watson -n '__fish_watson_using_command log' -s f -l from -d "Start date for log"
complete -f -c watson -n '__fish_watson_has_from log' -s t -l to -d "end date for log"
complete -f -c watson -n '__fish_watson_using_command log' -s y -l year -d "show the last year"
complete -f -c watson -n '__fish_watson_using_command log' -s m -l month -d "show the last month"
complete -f -c watson -n '__fish_watson_using_command log' -s w -l week -d "show week-to-day"
complete -f -c watson -n '__fish_watson_using_command log' -s d -l day -d "show today"
complete -f -c watson -n '__fish_watson_using_command log' -s a -l all -d "show all"
complete -f -c watson -n '__fish_watson_using_command log' -s p -l project -d "restrict to project" -a "(__fish_watson_get_projects)"
complete -f -c watson -n '__fish_watson_using_command log' -s T -l tag -d "restrict to tag" -a "(__fish_watson_get_tags)"
complete -f -c watson -n '__fish_watson_using_command log' -s j -l json -d "output json"
complete -f -c watson -n '__fish_watson_using_command log' -s g -l pager -d "view through pager"
complete -f -c watson -n '__fish_watson_using_command log' -s G -l no-pager -d "don't vew through pager"
# merge
complete -f -c watson -n '__fish_watson_needs_sub' -a merge -d "merge existing frames with conflicting ones"
complete -f -c watson -n '__fish_watson_using_command merge' -s f -l force -d "silently merge"
# remove
complete -f -c watson -n '__fish_watson_needs_sub' -a remove -d "Remove a frame"
complete -f -c watson -n '__fish_watson_using_command remove' -a "(__fish_watson_get_frames)"
complete -f -c watson -n '__fish_watson_using_command remove' -s f -l force -d "silently remove"
# rename
complete -f -c watson -n '__fish_watson_needs_sub' -a rename -d "Rename a project or tag"
complete -f -c watson -n '__fish_watson_using_command rename' -a "(__fish_watson_get_projects) (__fish_watson_get_tags)"
# report
complete -f -c watson -n '__fish_watson_needs_sub' -a report -d "Display a report of time spent"
complete -f -c watson -n '__fish_watson_using_command report' -s c -l current -d "include the running frame"
complete -f -c watson -n '__fish_watson_using_command report' -s C -l no-current -d "exclude the running frame (default)"
complete -f -c watson -n '__fish_watson_using_command report' -s f -l from -d "Start date for report"
complete -f -c watson -n '__fish_watson_has_from report' -s t -l to -d "end date for report"
complete -f -c watson -n '__fish_watson_using_command report' -s y -l year -d "show the last year"
complete -f -c watson -n '__fish_watson_using_command report' -s m -l month -d "show the last month"
complete -f -c watson -n '__fish_watson_using_command report' -s w -l week -d "show week-to-day"
complete -f -c watson -n '__fish_watson_using_command report' -s d -l day -d "show today"
complete -f -c watson -n '__fish_watson_using_command report' -s a -l all -d "show all"
complete -f -c watson -n '__fish_watson_using_command report' -s p -l project -d "restrict to project" -a "(__fish_watson_get_projects)"
complete -f -c watson -n '__fish_watson_using_command report' -s T -l tag -d "restrict to tag" -a "(__fish_watson_get_tags)"
complete -f -c watson -n '__fish_watson_using_command report' -s j -l json -d "output json"
complete -f -c watson -n '__fish_watson_using_command report' -s g -l pager -d "view through pager"
complete -f -c watson -n '__fish_watson_using_command report' -s G -l no-pager -d "don't vew through pager"
complete -f -c watson -n '__fish_watson_needs_sub' -a restart -d "Restart monitoring time for a stopped project"
complete -f -c watson -n '__fish_watson_using_command restart' -s s -l stop -d "stop running project"
complete -f -c watson -n '__fish_watson_using_command restart' -s S -l no-stop -d "do not stop running project"
complete -f -c watson -n '__fish_watson_using_command restart' -a "(__fish_watson_get_frames)"
# start
complete -f -c watson -n '__fish_watson_needs_sub' -a start -d "Start monitoring time for a project"
complete -f -c watson -n '__fish_watson_needs_project start' -a "(__fish_watson_get_projects)"
complete -f -c watson -n '__fish_watson_has_project start' -a "+(__fish_watson_get_tags)"
# status
complete -f -c watson -n '__fish_watson_needs_sub' -a status -d "Display when the current project was started and time spent"
complete -f -c watson -n '__fish_watson_using_command status' -s p -l project -d "only show project"
complete -f -c watson -n '__fish_watson_using_command status' -s t -l tags -d "only show tags"
complete -f -c watson -n '__fish_watson_using_command status' -s e -l elapsed -d "only show elapsed time"

119
dot_config/fish/config.fish.tmpl Executable file
View File

@@ -0,0 +1,119 @@
# vim: fdm=marker ft=fish.go-template
# login to X [[[ #
{{ if eq .chezmoi.username "kevin" }}
if status is-login
if test -z "$DISPLAY" -a $XDG_VTNR = 1
exec startx -- -keeptty
end
end
set -x GPG_TTY (tty)
{{ end }}
# ]]] login to X #
# fish-specific [[[ #
fish_vi_key_bindings
set -x EDITOR nvim
set -x VISUAL nvim
set -U fish_help_browser firefox
builtin cd $last_dir
bind \ce edit_command_buffer
bind \cr forward-word
chezmoi apply
~/scripts/sync-shortcuts
# source ~/.config/fish/key_abbr.fish > /dev/null
set -U fish_fxn_dir "{{ .chezmoi.homedir }}/linux-config/dot_config/fish/functions"
# set -U fish_fxn_dir "~/.config/fish/functions"
abbr ff "cd $fish_fxn_dir"
for fxn in (find $fish_fxn_dir -name '*.fish')
source $fxn
end
abbr rf "chezmoi apply && sync-shortcuts && source ~/.config/fish/key_abbr.fish > /dev/null"
abbr rfc "chezmoi apply && source ~/.config/fish/config.fish"
abbr xf "fish_config"
abbr f. "cd .."
abbr f.. "cd ../.."
# ]]] fish-specific #
# universal var's [[[ #
# spv
{{ if eq .chezmoi.fullHostname "nzxt" }}
set -U spv_dir "~/coding/spotify-lib-vis"
set -U mfs_dir "~/coding/mf-site"
{{ end }}
set -x PATH $PATH ~/scripts ~/scripts/colors ~/go/bin
set -x LD_LIBRARY_PATH $LD_LIBRARY_PATH /usr/local/lib /usr/local/lib64
set -x PKG_CONFIG_PATH $PKG_CONFIG_PATH /usr/lib/pkgconfig
set -x PASSWORD_STORE_CLIP_TIME 120
set -xU XSET_RATE 90
set -xU XSET_DELAY 200
# causes xmodmap to have issues when opening terminal sometimes
# xmodmap ~/.Xmodmap && xset r rate $XSET_DELAY $XSET_RATE
{{ if and (eq .chezmoi.fullHostname "x1-carbon") (not (eq .chezmoi.username "root")) }}
xset r rate $XSET_DELAY $XSET_RATE
{{ end }}
# set -U BROWSER "chromium"
set -U BROWSER "firefox"
# ]]] universal var's #
# fxn abbr's [[[ #
abbr ag "grep-aliases"
abbr bq "benq-brightness"
abbr cpc "copy cat"
abbr cpe "copy echo"
abbr cpp "copy echo (pwd)"
abbr cff "create-fish-function"
abbr ev "evince-silent"
# git [[[ #
abbr gcamp "git-amend-push"
abbr gdf "git-diff-files"
abbr gpsmt "git-push-multiple"
abbr gremotes "git-mult-remotes"
abbr grmb "git-delete-branch"
# ]]] git #
abbr hs "scan-history"
abbr hst "$EDITOR ~/.local/share/fish/fish_history"
abbr mt "math"
abbr pgr "grep-pdf"
abbr pgrf "grep-pdf-file"
abbr rs "redshift-set"
abbr ut "unix-timestamp"
abbr uzr "unzip-rm"
# ]]] fxn abbr's #
abbr hm "cd $mfs_dir && hugo serve -D --disableFastRender"
# school [[[ #
# 309
# abbr r0t "./revert-e3-json restaurants"
# abbr r0s "./revert-e3-json reservations"
# 369
abbr grc "grep-c"
abbr grh "grep-headers"
abbr rgh "rg-headers"
abbr r6 "run-a4 h e"
# abbr r6 "run-a3 f d o"
# abbr r6g "run-a3 f d g"
# abbr r6s "run-a3 s c o"
# abbr g6 "source $fish_fxn_dir/369/a3/gdb-a3-break.fish && gdb-a3-break c c"
# ]]] school #

View File

@@ -0,0 +1,5 @@
function carsim
printf '\033c'
# and ./carsim stop $argv[1] $argv[2]
and ./carsim light $argv[1] $argv[2]
end

View File

@@ -0,0 +1,15 @@
function gdb-a2
# gdb -ex "b safeStopSign.c:96" -ex "run" \
# gdb -ex "b safeTrafficLight.c:98" -ex "run" \
gdb -ex "run" -ex "bt" \
# gdb -ex "run" \
# -ex "p cur_lane_queue.count" \
# -ex "p cur_front->car->index" \
# -ex "p cur_front->car" \
# -ex "p cur_front" \
# --args ./carsim stop 1 4
# --args ./carsim stop 3 20
# --args ./carsim light 1 4
--args ./carsim light 1 20
# gdb -ex "b safeStopSign.c:86" -ex "run" --args ./carsim stop 1 10
end

View File

@@ -0,0 +1,30 @@
function gdb-a3-break
# 1 = trace file, 2 = alg
set trace_file 'traceprogs/tr-custom.ref'
set memsize 3
set swapsize 10
if test $argv[1] = 's'
set trace_file 'traceprogs/tr-simpleloop.ref'
set memsize 50
set swapsize 3000
end
set alg 'rand'
switch $argv[2]
case f
set alg 'fifo'
case l
set alg 'lru'
case c
set alg 'clock'
end
printf '\033c'
and bear make
and gdb \
# -ex "b pagetable.c:69" \
# -ex "b sim.c:158" \
-ex "b clock.c:29" \
-ex "run" \
--args ./sim -f $trace_file -m $memsize -s $swapsize -a $alg
end

View File

@@ -0,0 +1,49 @@
function run-a3
# 1 = alg, 2 = trace file, 3 = output
set memsize 3
set swapsize 10
set alg 'rand'
switch $argv[1]
case f
set alg 'fifo'
set trace_file 'traceprogs/tr-fifo.ref'
case l
set alg 'lru'
set trace_file 'traceprogs/tr-lru.ref'
case c
set alg 'clock'
set trace_file 'traceprogs/tr-clock.ref'
end
switch $argv[2]
case c
set trace_file 'traceprogs/tr-custom.ref'
case s
set trace_file 'traceprogs/tr-simpleloop.ref'
set memsize 50
set swapsize 3000
case m
set trace_file 'traceprogs/tr-matmul.ref'
set memsize 100
set swapsize 3000
end
printf '\033c'
# and bear make clean
and bear make
switch $argv[3]
case f
./sim -f $trace_file -m $memsize -s $swapsize -a $alg > a3.out 2>&1
case g
gdb -ex "run" -ex "bt" -ex "q" \
--args ./sim -f $trace_file -m $memsize -s $swapsize -a $alg
case o
./sim -f $trace_file -m $memsize -s $swapsize -a $alg
end
if test (count swapfile.*) -gt 0
rm swapfile.*
end
end

View File

@@ -0,0 +1,5 @@
function block-to-line
set block_size 1024
set bytes_per_line 16
math "($block_size*$argv[1])/$bytes_per_line + 1"
end

View File

@@ -0,0 +1,15 @@
function revert-image
set img_file 'emptydisk.img'
switch $argv[1]
case 1
set img_file 'onefile.img'
case m
set img_file 'multilevel.img'
case l
set img_file 'largefile.img'
case s
set img_file 'symlink.img'
end
cp imgs{-cp,}/$img_file
end

View File

@@ -0,0 +1,12 @@
function hex
switch $argv[1]
case h
# print dec/bin.
printf "%d " (echo "ibase=16;obase=A;$argv[2]" | bc)
printf "%d\n" (echo "ibase=16;obase=2;$argv[2]" | bc)
case d
# print hex/bin.
printf "%s " (echo "obase=16;$argv[2]" | bc)
printf "%d\n" (echo "obase=2;$argv[2]" | bc)
end
end

View File

@@ -0,0 +1,3 @@
function mount-image
sudo mount $argv[1] /mnt/369-a4
end

View File

@@ -0,0 +1,35 @@
function run-a4
# 1 = ex, 2 = img
printf '\033c'
# and bear make clean
bear make
set img_file 'imgs/emptydisk.img'
switch $argv[2]
case 1
set img_file 'imgs/onefile.img'
case m
set img_file 'imgs/multilevel.img'
case l
set img_file 'imgs/largefile.img'
case s
set img_file 'imgs/symlink.img'
end
switch $argv[1]
case h
./ext2_helpers_tester $img_file
case hg
gdb -ex "run" -ex "bt" -ex "q" \
--args ./ext2_helpers_tester './imgs/multilevel.img' '/level1/level2/level3//'
case m
./ext2_mkdir $img_file '/'
# ./ext2_mkdir 'imgs/multilevel.img' '/level1/level2/bfile'
case rg
./readimage $img_file
gdb -ex "run" -ex "bt" -ex "q" \
--args ./readimage './imgs/symlink.img'
case '*'
./readimage $img_file
end
end

View File

@@ -0,0 +1,3 @@
function grep-c
grep -nr --include \*.c $argv[1] ./
end

View File

@@ -0,0 +1,3 @@
function grep-headers
grep --color=auto -nr --include \*.h $argv[1] ./
end

View File

@@ -0,0 +1,3 @@
function rg-headers
rg $argv[1] *.h
end

View File

@@ -0,0 +1,3 @@
function rgc
rg $argv[1] *.c
end

View File

@@ -0,0 +1,3 @@
function benq-brightness
xrandr --output HDMI-0 --gamma 1:0.8:0 --brightness (math $argv[1] / 100)
end

View File

@@ -0,0 +1,53 @@
#
# Wrap the builtin cd command to maintain directory history.
#
function cd --description "Change directory"
set -l MAX_DIR_HIST 25
if test (count $argv) -gt 1
printf "%s\n" (_ "Too many args for cd command")
return 1
end
# Skip history in subshells.
if status --is-command-substitution
builtin cd $argv
return $status
end
# Avoid set completions.
set -l previous $PWD
if test "$argv" = "-"
if test "$__fish_cd_direction" = "next"
nextd
else
prevd
end
return $status
end
# allow explicit "cd ." if the mount-point became stale in the meantime
if test "$argv" = "."
cd "$PWD"
return $status
end
builtin cd $argv
set -l cd_status $status
if test $cd_status -eq 0 -a "$PWD" != "$previous"
set -q dirprev
or set -l dirprev
set -q dirprev[$MAX_DIR_HIST]
and set -e dirprev[1]
set -g -a dirprev $previous
set -e dirnext
set -g __fish_cd_direction prev
set -U last_dir $PWD
lsd -a
end
return $cd_status
end

View File

@@ -0,0 +1,9 @@
function certbot-ssl
set domain_args ""
for domain in $argv
set -a domain_args "-d" $domain
end
echo sudo certbot certonly --manual --preferred-challenges=dns \
--email kevin.mok@live.ca --server https://acme-v02.api.letsencrypt.org/directory \
--agree-tos $domain_args
end

View File

@@ -0,0 +1,3 @@
function copy
$argv[1] $argv[2] | xclip -selection clipboard
end

View File

@@ -0,0 +1,5 @@
function create-fish-function
printf 'function %s\nend' $argv[1] > $fish_fxn_dir/$argv[1].fish
and cd $fish_fxn_dir
and $EDITOR $argv[1].fish
end

View File

@@ -0,0 +1,3 @@
function evince-silent
evince $argv[1] > /dev/null 2>&1&
end

View File

@@ -0,0 +1,3 @@
function find-vim-filetype
fd $argv[1] /usr/share/nvim/runtime/ftplugin /usr/share/nvim/runtime/syntax
end

View File

@@ -0,0 +1,5 @@
function git-amend-push
git add -A .
and git commit --amend --no-edit -S
and git push --force
end

View File

@@ -0,0 +1,4 @@
function git-delete-branch
git push origin --delete $argv[1]
and git branch -D $argv[1]
end

View File

@@ -0,0 +1,3 @@
function git-diff-files
git diff --name-only $argv[1] $argv[2]
end

View File

@@ -0,0 +1,5 @@
function git-mult-remotes
git remote set-url --add --push origin $argv[1]
and git remote set-url --add --push origin $argv[2]
and git remote -v
end

View File

@@ -0,0 +1,5 @@
function git-push-multiple
git remote set-url --add --push origin $argv[1]
and git remote set-url --add --push origin $argv[2]
and git remote -v
end

View File

@@ -0,0 +1,5 @@
function grep-aliases
set key_aliases ~/key_aliases
rg $argv[1] $key_aliases
# rg "^$argv[1]" $key_aliases
end

View File

@@ -0,0 +1,4 @@
function grep-pdf-file
pdfgrep -n $argv[1] -B $argv[2] -A $argv[3] (fd -e pdf --no-ignore-vcs) > grep-$argv[1].txt
and nvim grep-$argv[1].txt -c "/$argv[1]"
end

View File

@@ -0,0 +1,3 @@
function grep-pdf
pdfgrep -n $argv[1] (fd -e pdf --no-ignore-vcs)
end

View File

@@ -0,0 +1,3 @@
function pastebin
cat $argv[1] | curl -F 'sprunge=<-' http://sprunge.us
end

View File

@@ -0,0 +1,3 @@
function redshift-set
redshift -x && redshift -O (math "$argv[1] * 100")
end

View File

@@ -0,0 +1,7 @@
function scan-history
sudo systemctl start postgresql.service
# and systemctl status postgresql.service
and source $spv_dir/src/scripts/api-keys.sh
and $spv_dir/src/scripts/update-history.sh
and cat $spv_dir/src/api/management/commands/update-history.log | tail -n 1
end

View File

@@ -0,0 +1,3 @@
function shred-rm
shred $argv && rm $argv
end

View File

@@ -0,0 +1,3 @@
function ssh-bandit
sshpass -f p/$argv[1] ssh -p 2220 bandit$argv[1]@bandit.labs.overthewire.org
end

View File

@@ -0,0 +1,4 @@
# convert unix timestamp
function unix-timestamp
date -d @$argv[1]
end

View File

@@ -0,0 +1,4 @@
function unzip-rm
unzip $argv[1]
and rm $argv[1]
end

View File

@@ -0,0 +1,4 @@
function vsnp
set snips_dir "/home/kevin/.vim/plugged/vim-snippets/UltiSnips"
$EDITOR $snips_dir/$argv[1].snippets
end

View File

@@ -0,0 +1,3 @@
function wc-pdf
pdftotext $argv[1] - | wc -w
end