Skip to content

Commit

Permalink
feat(zsh): add git functions
Browse files Browse the repository at this point in the history
  • Loading branch information
AhmedAbdulrahman committed Dec 2, 2023
1 parent c1f830b commit 784e90d
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 0 deletions.
11 changes: 11 additions & 0 deletions zsh/functions/$
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# vim: set ts=4 sw=4 tw=80 ft=zsh et :
# Ever pasted "$ somecommand" into the terminal and gotten this error?
# -bash: $: command not found

# Begone, silly errors! Lazy copy + paste forever!! ETCETERA!!!!
#

unalias $ 2> /dev/null

echo 'Quit pasting in commands from the internet, you lazy bum.'
"$@"
20 changes: 20 additions & 0 deletions zsh/functions/git-deinit
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# vim: set ts=4 sw=4 tw=80 ft=zsh et :
# Simple tool to remove a git repo from somewhere. Just run `git deinit`

unalias unixtime 2> /dev/null

REPO_PATH=$(git rev-parse --show-toplevel)

if [[ -d "${REPO_PATH}/.git" ]]; then
read -p "De-initialize this git repo? [y/N]" -n 1 -r
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo
echo "Removing ${REPO_PATH}/.git…"
rm -rf "${REPO_PATH}/.git"
echo "Done ✓"
else
echo "Aborting…"
fi
else
echo "Not in a git repository"
fi
18 changes: 18 additions & 0 deletions zsh/functions/git-delete-tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# vim: set ts=4 sw=4 tw=80 ft=zsh et :
# Delete all git remote tags

unalias git-delete-tags 2> /dev/null

# Exit if git is not installed
(( $+commands[git] )) || return 0

# Taken from https://gist.github.com/okunishinishi/9424779

#Delete local tags.
git tag -l | xargs git tag -d
#Fetch remote tags.
git fetch
#Delete remote tags.
git tag -l | xargs git push --delete origin
#Delete local tags.
git tag -l | xargs git tag -d
15 changes: 15 additions & 0 deletions zsh/functions/git-nuke
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# vim: set ts=4 sw=4 tw=80 ft=zsh et :
# Nukes a branch locally and on the origin remote.

unalias git-nuke 2> /dev/null

# Exit if git is not installed
(( $+commands[git] )) || return 0

if [[ -z "$1" ]]; then
echo "USAGE: git-nuke Branch name"
return 1
fi

git branch -D "$1"
git push origin :"$1"
15 changes: 15 additions & 0 deletions zsh/functions/killport
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# vim: set ts=4 sw=4 tw=80 ft=zsh et :
# Kills all processes running on the specified port (e.g. 'killport 8080')

unalias killport 2> /dev/null

# Exit if git is not installed
(( $+commands[awk] )) || return 0

if [[ -z "$1" ]]; then
echo "USAGE: killport PORT"
return 1
fi


lsof -i tcp:"$1" | awk '(NR!=1) && ($1!="Google") && ($1!="firefox") {print $2}' | xargs kill

0 comments on commit 784e90d

Please sign in to comment.