Skip to content

Instantly share code, notes, and snippets.

@Harwood
Last active December 20, 2022 19:30
Show Gist options
  • Save Harwood/a0e1dcca64509cc35276a3dcffd69ea3 to your computer and use it in GitHub Desktop.
Save Harwood/a0e1dcca64509cc35276a3dcffd69ea3 to your computer and use it in GitHub Desktop.
Collection of fish shell functions
function cidr --description "return ip range for a domain"
dig $argv +short | xargs whois | grep CIDR | awk '{ print $2 }'
end
function clean-dev --description "Resets git repos to remote's state with master checkout"
src_dirs $HOME/Developer/*/ $HOME/GitHub/*/
for repo in $src_dirs
if [ -d $repo/.git ]
echo $repo
git -C $repo stash clear
git -C $repo fetch --all --multiple --prune --prune-tags --tags
git -C $repo checkout master --force
git -C $repo reset --hard origin/master
git -C $repo branch | grep -v "^\\*" | xargs git -C $repo branch -D
git -C $repo pull --all --autostash --gpg-sign --jobs=4 --progress --prune --recurse-submodules --stat --tags
end
end
end
alias cp='rsync --progress -ah'
alias dc='docker-compose'
function docker-purge --description 'Removes all locally stored containers and images'
docker container list --quiet | xargs docker container stop
docker container prune --force
docker image prune --all --force
end
/Users/harwood/.local/share/omf/themes/lambda/fish_prompt.fish
function git --wraps hub --description 'Alias for hub, which wraps git to provide extra functionality with GitHub.'
hub $argv
end
alias newsboat='env EDITOR=\'vim -u NONE\' newsboat'
function pip-update --description 'Updates all Python 2 & 3 packages'
switch (uname)
case Darwin
set permissions ''
case Linux
set permissions '-n1 sudo -H'
case '*'
set permissions ''
end
# update python 2
if hash pip2 2> /dev/null
echo 'Updating Python 2....'
pip2 list --outdated | tail -n +3 | awk '{ print $1 }' | xargs $permissions pip2 install --upgrade
end
# update python 3
if hash pip3 2> /dev/null
echo 'Updating Python 3....'
pip3 list --outdated | tail -n +3 | awk '{ print $1 }' | xargs $permissions pip3 install --upgrade
end
end
function pull-src --description 'Updates all source repos'
set -l src_dirs $HOME/Developer/* $HOME/GitHub/* $HOME/src/*
echo "----- Starting YADM -----"
yadm pull --all --autostash --gpg-sign --jobs=4 --progress --prune --recurse-submodules --stat --tags
echo "----- Finishing YADM -----"
echo ""
for dir in $src_dirs
if [ -d $dir/.git ]
echo "----- Starting $dir -----"
git -C $dir fetch --all --multiple --prune --prune-tags --tags
git -C $dir pull --all --autostash --gpg-sign --progress --prune --recurse-submodules --stat --tags
echo "----- Finishing $dir -----"
echo ""
else if [ -d $dir/.svn ]
echo "----- Starting svn update of $dir -----"
svn update $dir
echo "----- Finishing svn update of $dir -----"
echo ""
end
end
end
alias torcheck='curl --socks5 localhost:9050 --socks5-hostname localhost:9050 -s https://check.torproject.org/ | cat | grep -m 1 Congratulations | xargs'
alias tree='tree -CAFS'
function urldecode --description 'Urldecode string'
python3 -c "import sys, urllib.parse as parse; print(parse.unquote_plus('$argv'))"
end
function urlencode --description 'Urlencode string'
python3 -c "import sys, urllib.parse as parse; print(parse.quote_plus('$argv'))"
end
alias vi='vim -u NONE'
alias yadm='yadm --yadm-dir ~/.config/yadm'
# using https://fishshell.com/docs/current/commands.html#complete
complete --command yadm --wraps lab
function yadmUpdate
set currDate (date +%D-%H%M)
yadm checkout -b $currDate
yadm commit -S -m "Update in $currDate" ;and \
yadm checkout master ;and \
yadm merge $currDate ;and \
yadm push --set-upstream origin master
yadm branch --delete $currDate
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment