Skip to content

Instantly share code, notes, and snippets.

@devotox
Forked from jimmed/config.fish
Last active August 29, 2015 14:04
Show Gist options
  • Save devotox/e71bf99d62d836cb9d3f to your computer and use it in GitHub Desktop.
Save devotox/e71bf99d62d836cb9d3f to your computer and use it in GitHub Desktop.
# Aliases to common git methods
function gs; git status --short $argv; end;
function gd; git diff --color $argv; end;
function gf; git fetch -p; end;
function gpl; git pull $argv; end;
function gps; git push $argv; end;
function gch; git checkout $argv; end;
function gb; git branch $argv; end;
function ga; git add $argv; end;
function gco; git commit -m $argv; end;
# Just in case it's ever disabled :'(
git config --global --add color.ui true
# Handy alias for ls -la
function la; ls -la $argv; end;
# I edit my config too much
function fish-edit-config -d "Opens the fish configuration file for editing, and reloads it on quit"
set -l configPath ~/.config/fish/config.fish
vim $configPath
and . $configPath
end
# Delete Merged Branches - Arguments: branch to check if merged into
function git-delete-merged-branches -a main -d "Deletes all branches already merged into branch passed in args"
git branch -r --merged | grep -v $main | sed 's/origin\///' | xargs -n 1 git push --delete origin
git remote prune origin
end
# Helper methods
function read_confirm
while true
read -l -p read_confirm_prompt confirm
switch $confirm
case Y y
return 0
case '' N n
return 1
end
end
end
function read_confirm_prompt
echo 'Do you want to continue? [Y/n] '
end
# Methods for listing/deleting untracked files in git
function git-show-untracked-files -d "Shows untracked files in the repository"
echo (gs | grep -E '^\?\?' | cut -c 4-)
end
function git-delete-untracked-files -d "Deletes all untracked files in the repository. Dangerous!"
set -l files (git-show-untracked-files)
if test $files
echo "The following files will be deleted by this operation:"
echo $files
if read_confirm
for f in $files
rm $f
and echo "Deleted" $f
end
end
else
echo "There are no untracked files to delete."
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment