Skip to content

Instantly share code, notes, and snippets.

@iTrauco
Created June 23, 2025 23:22
Show Gist options
  • Save iTrauco/55980782b6c7fa08ef101493c51e8ccc to your computer and use it in GitHub Desktop.
Save iTrauco/55980782b6c7fa08ef101493c51e8ccc to your computer and use it in GitHub Desktop.
#!/bin/zsh
#################################################################
# πŸš€ GITHUB GIST ALIASES & FUNCTIONS
# Collection of aliases for managing GitHub Gists via gh CLI
# Author: @trauco
# Date Added: 2024-01-15
# Dependencies: gh (GitHub CLI), vim
#################################################################
#################################################################
# πŸ“ SINGLE FILE GIST CREATION
#################################################################
# 🎯 gistedit - Create NEW file in vim, save locally, then push to public gist
# Usage: gistedit test.sh (creates test.sh locally and on gist)
# Date Added: 2024-01-15
alias gistedit='function _gistedit(){
local filename="$1"
if [ -z "$filename" ]; then
echo "❌ Usage: gistedit <filename>"
return 1
fi
vim "$filename" # Create/edit NEW file in vim
# File is saved locally when you :wq in vim
gh gist create "$filename" --public # Upload to public gist after vim closes
}; _gistedit'
# πŸ“‹ gisteditdesc - Edit file then create public gist with description
# Usage: gisteditdesc myfile.py
# Date Added: 2024-01-15
alias gisteditdesc='function _gisteditdesc(){
local filename="$1"
if [ -z "$filename" ]; then
echo "❌ Usage: gisteditdesc <filename>"
return 1
fi
vim "$filename" # Edit file first
local description
echo "πŸ“ Enter description for the Gist: "
read description
gh gist create "$filename" --public --description "$description"
}; _gisteditdesc'
# πŸ”’ gistsecret - Create NEW file in vim, save locally, then push to private gist
# Usage: gistsecret private_notes.txt (creates private_notes.txt locally and on gist)
# Date Added: 2024-01-15
alias gistsecret='function _gistsecret() {
local filename="$1"
if [ -z "$filename" ]; then
echo "❌ Usage: gistsecret <filename>"
return 1
fi
vim "$filename" # Create/edit NEW file in vim
# File is saved locally when you :wq in vim
gh gist create "$filename" # Upload to private gist after vim closes (default is private)
}; _gistsecret'
#################################################################
# πŸ“¦ MULTI-FILE GIST CREATION
#################################################################
# 🌟 gistall - Create multiple NEW files in vim, save locally, then push all to public gist
# Usage: gistall file1.py file2.js README.md (creates all files locally and on gist)
# Date Added: 2024-01-15
function gistall() {
if [ "$#" -eq 0 ]; then
echo "❌ No files provided. Usage: gistall <file1> <file2> ... <fileN>"
return 1
fi
echo "πŸ“¦ Creating new files for public gist:"
# Create/edit each file in vim
for file in "$@"; do
echo " πŸ“ Creating: $file"
vim "$file" # Create each file locally
done
echo "πŸ“ Enter a description for the gist:"
read -r description
# Upload all files to public gist
gh gist create "$@" --public -d "$description"
echo "βœ… Public gist created with all files!"
}
# πŸ” gistpriv - Create multiple NEW files in vim, save locally, then push all to private gist
# Usage: gistpriv secrets.env config.json (creates all files locally and on gist)
# Date Added: 2024-01-15
function gistpriv() {
if [ "$#" -eq 0 ]; then
echo "❌ No files provided. Usage: gistpriv <file1> <file2> ... <fileN>"
return 1
fi
echo "πŸ”’ Creating new files for private gist:"
# Create/edit each file in vim
for file in "$@"; do
echo " πŸ“ Creating: $file"
vim "$file" # Create each file locally
done
echo "πŸ“ Enter a description for the gist:"
read -r description
# Upload all files to private gist (gh defaults to private)
gh gist create "$@" -d "$description"
echo "βœ… Private gist created with all files!"
}
#################################################################
# βš™οΈ ENVIRONMENT CONFIGURATION
#################################################################
# πŸ“ Set vim as the default editor for gh CLI operations
# Date Added: 2024-01-15
export GH_EDITOR=vim
#################################################################
# πŸ“š QUICK REFERENCE
# - gistedit: Quick public gist (single file with vim edit)
# - gisteditdesc: Public gist with description (single file)
# - gistsecret: Quick private gist (single file with vim edit)
# - gistall: Public gist (multiple files)
# - gistpriv: Private gist (multiple files)
#################################################################
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment