Skip to content

Instantly share code, notes, and snippets.

@rw3iss
Last active July 13, 2024 07:49
Show Gist options
  • Save rw3iss/7dfe23857bda1eafa262f2758ff58748 to your computer and use it in GitHub Desktop.
Save rw3iss/7dfe23857bda1eafa262f2758ff58748 to your computer and use it in GitHub Desktop.
.aliases
#alias reload="source ~/.bashrc";
alias reload="exec zsh -l"
alias aliases="cd ~/.profile && code . && cd -"
#alias alias=aliases
# Path shortcuts:
alias .='cd ~'
alias h='cd ~'
alias ~='cd ~'
alias ..='cd ..'
alias ...='cd ../../'
alias dl='cd ~/Downloads'
alias doc='cd ~/Documents'
alias s='cd ~/Sites'
alias n='cd ~/Documents/Notes'
alias p='cd ~/Projects'
alias 3d='cd ~/Documents/3D/git'
alias ard='cd ~/Documents/Arduino'
alias roa='cd ~/Documents/Arduino/Projects/Roaster'
alias lsa='ls -la'
# Servers:
alias 3k='ssh [email protected]'
alias rw='ssh 207.148.29.98'
alias mb='ssh [email protected]'
#Sites:
alias rwp="cd ~/Sites/ryanweiss/ryanweiss.net/rw-preact"
alias b="cd ~/Sites/blobs/src"
alias t="cd ~/Sites/tier33"
alias f="cd ~/Sites/forex-bot"
alias mu="cd ~/Sites/mu"
#------------------------------------------------------------------------------
# Misc system commands:
alias ch="cd ~ && code ."
alias hosts="cd /c/Windows/System32/drivers/etc && code hosts" # edit hosts file with vscode
#alias acli='~/bin/arduino-cli.exe'
alias acli='arduino-cli'
# unix/ubuntu stuff:
alias update='sudo apt update -y && sudo apt upgrade' # Update all package and upgrade system
alias size='du -sh .' # get size of current directory
alias inputs="pactl list short sources" # list audio inputs
alias rsaudio="pulseaudio -k && sudo alsa force-reload" # restart audio engine
# npm commands:
alias nr="npm run --"
alias ni='npm i --'
alias dev="npm run dev"
alias d="npm run dev"
alias st="npm start"
alias devnt="npm run dev-nt"
alias logs="npm run logs"
alias ninit="echo 'Deleting node_modules and running npm install...' && rm -rf node_modules && rm -f package-lock.json && npm i"
#-------------------------------------------------------------------------------
# Grep for a string in a given folder:
_grep() {
string=$1
folder="."
if [ -z "$2" ]
then
echo "No search directory given, using current directory."
else
folder=$2
fi
printf "Looking for '$string' in $folder \n\n"
sudo /bin/grep -Rn --exclude-dir={/run} "$folder" -e "$string"
}
# usage: gr string folder
alias gr=_grep
#-------------------------------------------------------------------------------
# Find a file by name:
_find() {
string=$1
folder="."
if [ -z "$2" ]
then
echo "No search directory given, using current directory."
else
folder=$2
fi
printf "Looking for filename '$string' in $folder \n\n"
sudo /bin/find "$folder" -name "$string" -print
}
alias f=_find
#-------------------------------------------------------------------------------
# Tar/Untar a directory:
tar() {
filename=$1
if [ -z "$2" ]
then
echo "No output filename supplied, using '$1'"
else
filename=$2
fi
/bin/tar cvfz $filename.tar.gz $1
}
untar() {
/bin/tar xvfz $1
}
alias tar=tar
alias untar=untar
#-------------------------------------------------------------------------------
# Networking:
getPortProcesses() {
lsof -i ':'$1
}
alias pp=getPortProcesses
portKillProcess() {
echo "Killing process on port $1..."
#lsof -ti tcp:$1 | xargs kill -9
#echo "netstat -an | grep :$1 | awk '{print \$5}' | xargs -r -L1 tskill"
echo "kill -kill `lsof -t -i tcp:$1`"
kill -kill `lsof -t -i tcp:$1`
# netstat -an | grep :$1 | awk '{print $5}'
# netstat -an | grep :$1 | awk '{print $5}' | xargs -r -L1 tskill
}
alias pk=portKillProcess
portKillProcess_Windows() {
echo "Killing process on port $1..."
echo "netsat -ano | findstr :$1 | awk '{print $5}' | xargs -r -L1 tskill"
netsat -ano | findstr :$1 | awk '{print $5}' | xargs -r -L1 tskill
}
alias pkw=portKillProcess_Windows
#-------------------------------------------------------------------------------
# Applications:
#alias nordvpn connect to US:
alias nord="nordvpn connect New_York"
alias norddc="ordvpn disconnect"
# Django / Python
#alias python='python3'
alias dr='python manage.py runserver'
# Mysql:
#alias mysql='sudo mysql -uroot -pqazokm1001';
alias mysqlstart='sudo /etc/init.d/mysql start'
alias mysqlstop='sudo /etc/init.d/mysql stop'
# Postgres:
alias ps='sudo -u postgres psql'
#-------------------------------------------------------------------------------
# Git commands:
# gac = add, commit with message arg1
git_add_commit() {
echo git add .
echo git commit -m "$1"
git add .
git commit -m "$1"
}
# gcp = add, commit with message arg1, and push to arg2
git_commit_push() {
branch='develop'
message='(no commit message)'
if [ -z "$1" ]; then
echo "No message supplied, using '$message'."
else
message=$1
fi
if [ -z "$2" ]; then
branch=$(git branch | sed -n 's/* \(.*\)/\1/p')
else
branch=$2
fi
echo git add .
echo git commit -m \"$message\" --no-verify
echo git push origin $branch
git add .
git commit -m "$message" --no-verify
git push origin $branch
}
# ginit = initialize a new repository
git_init_add_push() {
branch='master'
message='Initial creation.'
if [ -z "$1" ]; then
echo "Command format: ginit <repo-url> <branch>"
return 0
fi
if [ -z "$2" ]; then
branch=$(git branch | sed -n 's/* \(.*\)/\1/p')
#echo "No branch supplied, using '$branch'."
else
branch=$2
fi
echo git init
echo git remote add origin $1
do_commit $message $branch
git init
git remote add origin $1
do_commit $message $branch
}
# gcpk = add, commit with message arg1
git_cherry_pick() {
echo git cherry-pick --no-commit $@
git cherry-pick --no-commit $@
}
# gc = git checkout to branch arg1
git_checkout() {
branch='master'
if [ -z "$1" ]; then
branch=$(git branch | sed -n 's/* \(.*\)/\1/p')
#echo "No branch supplied, using '$branch'."
else
branch=$1
fi
echo git checkout $branch
git checkout $branch
}
# gp = git pull from repo arg1, branch arg2
git_pull() {
repo='origin'
branch='develop'
if [ "$2" ]; then # branch and git_pull supplied
# echo "Pulling repo: '$repo', branch: '$branch'."
repo=$1
branch=$2
else
if [ -z "$1" ]; then
branch=$(git branch | sed -n 's/* \(.*\)/\1/p')
#echo "No repo or branch supplied, using current: '$repo $branch'."
else
branch=$1
fi
fi
echo git pull $repo $branch
git pull $repo $branch
}
# gm = git merge origin arg1
git_merge() {
branch='develop'
if [ -z "$1" ]; then
branch=$(git branch | sed -n 's/* \(.*\)/\1/p')
else
branch=$1
fi
echo git merge origin $branch
git merge origin $branch
}
# gmc = git merge from $1 into $1
git_merge_commit() {
echo "DONT USE THIS"
# branchFrom='develop'
# branchInto='develop'
# if [[ -z "$1" && -z "$2" ]]; then
# echo "Syntax: gmc <from> <to>"
# return 0
# fi
# if [ -z "$1" ]; then
# echo "Need to supply from and to branches as arguments."
# return 0
# else
# branchFrom=$1
# fi
# if [ -z "$2" ]; then
# echo "No into branch given, using '$branchInto'."
# else
# branchInto=$2
# fi
# git fetch -a
# git checkout $branchInto
# git pull origin $branchInto
# git merge $branchFrom
# git_commit_push "merged $branchFrom" $branchInto
# git checkout $branchFrom
}
git_fetch() {
echo "git fetch -a"
git fetch -a
}
git_reset() {
echo "git reset --hard"
git reset --hard
}
git_help() {
echo "Git aliases:"
echo "alias gh=git_help"
echo "alias gac=git_add_commit"
echo "alias gcp=git_commit_push"
echo "alias gph='git add . && git commit -m 'Latest' && git push heroku master'"
echo "alias ginit=git_init_add_push"
echo "alias gb='git branch -a'"
echo "alias gl='git show-branch -r'"
echo "alias mgs='mgitstatus'"
echo "alias gs='git status -b -s --ahead-behind'"
echo "alias gp=git_pull"
echo "alias gc=git_checkout"
echo "alias gd='git diff'"
echo "alias gdf='git diff --name-only'"
echo "alias gm=git_merge"
echo "alias gmc=git_merge_commit"
echo "alias gcpk=git_cherry_pick"
echo "alias gf='git fetch -a'"
echo "alias gr=git_reset"
}
git_branch_delete() {
if [ -z "$1" ]; then
echo "Must supply a branch name."
return
fi
branch=$1
echo git push -d origin $branch
echo git branch -D $branch
git push -d origin $branch
git branch -D $branch
}
alias gh=git_help
alias gac=git_add_commit
alias gcp=git_commit_push
alias gph='git add . && git commit -m 'Latest' && git push heroku master'
alias ginit=git_init_add_push
alias gb="git branch -a"
alias gl="git show-branch -r"
alias mgs="mgitstatus"
alias gs="git status -b -s --ahead-behind"
alias gp=git_pull
alias gc=git_checkout
alias gd="git diff"
alias gdf="git diff --name-only"
alias gm=git_merge
alias gmc=git_merge_commit
alias gcpk=git_cherry_pick
alias gf=git_fetch
alias gr=git_reset
alias gbdl=git_branch_delete
source ~/.profile/.aliases
source ~/.profile/.aliases.git
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment