Skip to content

Instantly share code, notes, and snippets.

@sharik709
Created April 22, 2025 06:18
Show Gist options
  • Save sharik709/41ad4271efcefe32ba89d4e222fa8792 to your computer and use it in GitHub Desktop.
Save sharik709/41ad4271efcefe32ba89d4e222fa8792 to your computer and use it in GitHub Desktop.
My Custom Terminal Functions
# ---------------------------
# File: ~/.custom_funcs
# ---------------------------
# --- Git Helpers ---
# Push current branch
function push() {
git push origin "$(git branch --show-current)"
}
# Rebase current branch onto main
function grebase() {
git fetch origin main && git rebase origin/main
}
# Auto commit all with message
function gsave() {
git add . && git commit -m "${1:-'autosave'}"
}
# Clone and cd
function gclone() {
git clone "$1" && cd "$(basename "$1" .git)"
}
# Show branches by last commit date
function glatest() {
git for-each-ref --sort=-committerdate refs/heads/ --format='%(refname:short) - %(committerdate:relative)'
}
# Delete merged branches except current and main
function gcleanup() {
git branch --merged | grep -v "\*" | grep -v "main" | xargs -n 1 git branch -d
}
# Open PR for current branch
function gpr() {
open "https://github.com/$(git remote get-url origin | sed -E 's/.*github.com[/:](.*)\.git/\1/')/compare/$(git branch --show-current)?expand=1"
}
# --- System / Navigation ---
# Backup any file quickly
function backup() {
cp "$1" "$1.bak"
}
# Make and cd
function mkcd() {
mkdir -p "$1" && cd "$1"
}
# Extract any archive
function extract() {
if [ -f "$1" ]; then
case "$1" in
*.tar.bz2) tar xjf "$1" ;;
*.tar.gz) tar xzf "$1" ;;
*.bz2) bunzip2 "$1" ;;
*.rar) unrar x "$1" ;;
*.gz) gunzip "$1" ;;
*.tar) tar xf "$1" ;;
*.tbz2) tar xjf "$1" ;;
*.tgz) tar xzf "$1" ;;
*.zip) unzip "$1" ;;
*.Z) uncompress "$1" ;;
*.7z) 7z x "$1" ;;
*) echo "'$1' cannot be extracted via extract()" ;;
esac
else
echo "'$1' is not a valid file"
fi
}
# Get current IP quickly
function myip() {
curl -s ifconfig.me
}
# --- Dev Helpers ---
# Quick HTTP server
function servehere() {
python3 -m http.server "${1:-8000}"
}
# Kill port
function killport() {
lsof -ti:"$1" | xargs kill -9
}
# Check size of each folder
function dus() {
du -sh ./* | sort -h
}
# Open project in VSCode
function ocode() {
code "$(pwd)"
}
# Search in files
function fsearch() {
grep -rnw . -e "$1"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment