Last active
June 10, 2023 03:01
-
-
Save arthurattwell/3703a1a88c13e4ef08d56c744109f080 to your computer and use it in GitHub Desktop.
Aliases for OSX Terminal and Windows command-prompt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
######################################### | |
# Terminal aliases | |
# OSX: Save/add this to ~/.bash_profile | |
# Ubuntu: Add this to ~/.bashrc | |
# Windows Git Bash: Add this to ~/.bashrc | |
######################################### | |
# Uncomment one of the following two options | |
# - This for OSX: | |
# alias aliedit="code ~/.bash_profile" | |
# - Or this for Ubuntu: | |
alias aliedit="code ~/.bashrc" | |
# - Or this for Git Bash on Windows | |
# unless https://superuser.com/a/1209410 | |
# alias aliedit="code ~/.bash_profile" | |
# Customise shell prompt if in Windows Git Bash | |
if [[ $OSTYPE =~ msys* ]] | |
then | |
PS1='\[\033]0;$TITLEPREFIX:$PWD\007\]\n\[\033[32m\]\u \[\033[33m\]\w\[\033[36m\]`__git_ps1`\[\033[0m\]\n$ ' | |
fi | |
# If WSL... | |
if [[ "$OSTYPE" == "linux-gnu" ]] | |
then | |
# Load SSL agent | |
eval "$(ssh-agent -s)" | |
ssh-add /mnt/c/Users/Arthur/.ssh/id_rsa | |
# Add .local/bin to path for Ansible | |
PATH=$HOME/.local/bin:$PATH | |
fi | |
# Turn off annoying 'Default Beep' sound in Windows Bash | |
bind "set bell-style none" | |
# Shell commands | |
alias l="ls" | |
# Launch apps | |
alias bash="start C:/cygwin64/bin/bash.exe" | |
alias cyg="start C:/cygwin64/bin/bash.exe" | |
# Git shortcuts | |
alias gpl="git pull" | |
alias gps="git push" | |
alias gpso="git push origin" | |
alias gpsb="git push Bitbucket" | |
alias gpst="git push --tags" | |
alias gpstf="git push --tags -f" | |
alias ga="git add" | |
alias gaa="git add ." | |
alias gaaa="git add -A" | |
alias gb="git branch" | |
alias gbd="git branch -d" | |
alias gbv="git branch -v" | |
alias gc="git commit" | |
alias gcm="git commit -m" | |
alias gco="git checkout" | |
alias gcob="git checkout -b" | |
alias gcof="git checkout --" | |
alias gcom="git checkout master" | |
alias gcod="git checkout develop" | |
alias gcol="git checkout live" | |
alias gd="git diff" | |
alias gda="git diff HEAD" | |
alias gf="git fetch" | |
alias gg="git gui" | |
alias gi="git init" | |
alias gl="git log" | |
alias glg="git log --graph --oneline --decorate --all" | |
alias gld="git log --pretty=format:'%h %ad %s' --date=short --all" | |
alias glog="git log --pretty=format:%%h -n 1" | |
alias ghc="git log --pretty=format:%%h -n 1^ | xclip" | |
alias gmg="git merge --no-ff" | |
alias gs="git status" | |
alias gss="git status -s" | |
alias gst="git stash" | |
alias gsta="git stash apply" | |
alias gstl="git stash list" | |
alias gstp="git stash pop" | |
alias gstd="git stash drop" | |
# File management | |
alias open="explorer.exe ." | |
# Useful paths | |
# (Adjust paths per system) | |
alias src="cd /c/src" | |
alias core="cd /c/src/core" | |
alias ebt="cd /c/src/electric-book" | |
alias ebm="cd /c/src/electric-book-gui" | |
alias ebw="cd /c/src/electricbookworks" | |
alias manage="cd /c/src/manage" | |
alias temp="cd /c/temp" | |
alias squid="cd /c/src/booksquid" | |
alias squidm="cd /c/src/booksquid-mailer" | |
alias hbam="cd /c/src/howbooksaremade" | |
alias ebe="cd /c/src/electric-book-electron" | |
if [[ "$OSTYPE" == "linux-gnu" ]] | |
then | |
alias src="cd /mnt/c/src" | |
alias core="cd /mnt/c/src/core" | |
alias ebt="cd /mnt/c/src/electric-book" | |
alias ebm="cd /mnt/c/src/electric-book-gui" | |
alias ebw="cd /mnt/c/src/electricbookworks" | |
alias manage="cd /mnt/c/src/manage" | |
alias temp="cd /mnt/c/temp" | |
alias squid="cd /mnt/c/src/booksquid" | |
alias squidm="cd /mnt/c/src/booksquid-mailer" | |
alias hbam="cd /mnt/c/src/howbooksaremade" | |
alias ebe="cd /mnt/c/src/electric-book-electron" | |
fi | |
# Open files | |
alias sites="code /c/src/manage/sites.txt" | |
# for Windows Git bash only, enable the Linux xdg-open | |
# command to work in Windows. First, we create a function | |
# called xdgopen (functions can't have dashes) which | |
# on Windows will run `start`, followed by the file to open. | |
# Then we map the alias `xdg-open` to our no-dashes function name. | |
if [[ $OSTYPE =~ msys* ]] | |
then | |
xdg-open() | |
{ | |
start $1 | |
} | |
export -f xdg-open | |
alias xdg-open="xdgopen" | |
# Fix path for WSL | |
alias sites="code /mnt/c/src/manage/sites.txt" | |
fi | |
# Jekyll | |
alias js="bundle exec jekyll serve" | |
alias jsi="bundle exec jekyll serve --incremental" | |
alias jsb0="bundle exec jekyll serve --baseurl=''" | |
alias jsb0i="bundle exec jekyll serve --baseurl='' --incremental" | |
alias jsib0="bundle exec jekyll serve --baseurl='' --incremental" | |
alias jb="bundle exec jekyll build" | |
alias jbb0="bundle exec jekyll build --baseurl=''" | |
alias jb-epub="bundle exec jekyll build --config='_config.yml,_configs/_config.epub.yml'" | |
alias jb-app="bundle exec jekyll build --config='_config.yml,_configs/_config.app.yml'" | |
alias jsi-app="bundle exec jekyll serve --incremental --config='_config.yml,_configs/_config.app.yml'" | |
alias js-epub="bundle exec jekyll serve --config='_config.yml,_configs/_config.epub.yml'" | |
alias jsi-epub="bundle exec jekyll serve --incremental --config='_config.yml,_configs/_config.epub.yml'" | |
alias jsi-print="bundle exec jekyll serve --incremental --config='_config.yml,_configs/_config.print-pdf.yml'" | |
alias js-live="bundle exec jekyll serve --config='_config.yml,_configs/_config.live.yml'" | |
alias jb-live="bundle exec jekyll build --config='_config.yml,_configs/_config.live.yml'" | |
alias jsi-live="bundle exec jekyll serve --incremental --config='_config.yml,_configs/_config.live.yml'" | |
# Electric Book commands | |
alias rl="./run-linux.sh" | |
alias eb="npm run eb" | |
# BrowserSync | |
# browsersync.io | |
alias bsync='browser-sync start --server "_site" --files "*.*"' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:::::::::::::::::::::::::::::::::::::: | |
:: :: | |
:: Windows Command Prompt aliases :: | |
:: :: | |
:::::::::::::::::::::::::::::::::::::: | |
@echo off | |
DOSKEY alias=echo Listing all aliases in aliases.bat ^& if ".$*." == ".." ( DOSKEY /MACROS ) else ( DOSKEY $* ) | |
DOSKEY aliedit=echo edit aliases in "C:\Users\Arthur\AppData\Roaming\aliases.bat" ^& notepad C:\Users\Arthur\AppData\Roaming\aliases.bat | |
:: Unix commands | |
DOSKEY l=echo dir ^& DIR $* | |
DOSKEY ls=echo dir ^& DIR $* | |
DOSKEY mv=echo move ^& MOVE $* | |
DOSKEY h=echo doskey ^/history ^& DOSKEY /HISTORY | |
:: Git shortcuts | |
DOSKEY gpl=echo git pull ^& git pull | |
DOSKEY gps=echo git push ^& git push | |
DOSKEY gpso=echo git push origin ^& git push origin | |
DOSKEY gpsb=echo git push Bitbucket ^& git push Bitbucket | |
DOSKEY ga=echo git add ... ^& git add $* | |
DOSKEY gaa=echo git add ^. ^& git add . | |
DOSKEY gaaa=echo git add -A ^& git add -A | |
DOSKEY gb=echo git branch ^& git branch | |
DOSKEY gbd=echo git branch -d ... ^& git branch -d $* | |
DOSKEY gbv=echo git branch -v ... ^& git branch -v $* | |
DOSKEY gc=echo git commit ^& git commit | |
DOSKEY gcm=echo git commit -m ... ^& git commit -m $* | |
DOSKEY gco=echo git checkout ... ^& git checkout $* | |
DOSKEY gcob=echo git checkout -b ... ^& git checkout -b $* | |
DOSKEY gcof=echo git checkout -- ... ^& git checkout -- $* | |
DOSKEY gcom=echo git checkout master ^& git checkout master | |
DOSKEY gcod=echo git checkout develop ^& git checkout develop | |
DOSKEY gd=echo git diff ^& git diff | |
DOSKEY gda=echo git diff HEAD ^& git diff HEAD | |
DOSKEY gf=echo git fetch ^& git fetch | |
DOSKEY gg=echo git gui ^& git gui | |
DOSKEY gi=echo git init ^& git init | |
DOSKEY gl=echo git log ^& git log | |
DOSKEY glg=echo git log --graph --oneline --decorate --all ^& git log --graph --oneline --decorate --all | |
DOSKEY gld=echo git log --pretty=format:"..." --date=short --all ^& git log --pretty=format:"%h %ad %s" --date=short --all | |
DOSKEY glog=echo git log --pretty=format:%%h -n 1 ^& git log --pretty=format:%%h -n 1 | |
DOSKEY ghc=git log --pretty=format:%%h -n 1^|clip ^& echo Short hash copied to clipboard | |
DOSKEY gmg=echo git merge --no-ff ^& git merge --no-ff | |
DOSKEY gs=echo git status ^& git status | |
DOSKEY gss=echo git status -s ^& git status -s | |
DOSKEY gst=echo git stash ^& git stash | |
DOSKEY gstl=echo git stash list ^& git stash list | |
DOSKEY gstp=echo git stash pop ^& git stash pop | |
DOSKEY gstd=echo git stash drop ^& git stash drop | |
:: Give git status for all subdirectories | |
DOSKEY gsa=@echo off ^& for /f "tokens=*" %%a in ('dir /ad /b') do (echo ---------------------------------------------------- $T echo %%a $T git --git-dir=%%a/.git --work-tree=%%a status) | |
:: File management | |
DOSKEY open=start . | |
:: Sublime Text | |
DOSKEY sublime="C:\Program Files\Sublime Text 3\sublime_text.exe" | |
:: Use paths | |
DOSKEY src=cd /d c:\src | |
DOSKEY core=cd /d c:\src\core | |
DOSKEY eb=cd /d c:\src\electric-book | |
DOSKEY ebm=cd /d c:\src\electric-book-gui | |
DOSKEY ebw=cd /d c:\src\electricbookworks | |
DOSKEY manage=cd /d c:\src\manage | |
DOSKEY wrt=cd /d c:\src\write | |
DOSKEY temp=cd /d c:\temp | |
:: Open files | |
DOSKEY sites=c:\src\manage\sites.txt | |
:: Jekyll | |
DOSKEY js=echo bundle exec jekyll serve ^& bundle exec jekyll serve | |
DOSKEY jsi=echo bundle exec jekyll serve --incremental ^& bundle exec jekyll serve --incremental | |
DOSKEY jsb0=echo bundle exec jekyll serve --baseurl="" ^& bundle exec jekyll serve --baseurl="" | |
DOSKEY jsb0i=echo bundle exec jekyll serve --baseurl="" --incremental ^& bundle exec jekyll serve --baseurl="" --incremental | |
DOSKEY jsib0=echo bundle exec jekyll serve --baseurl="" --incremental ^& bundle exec jekyll serve --baseurl="" --incremental | |
DOSKEY jb=echo bundle exec jekyll build ^& bundle exec jekyll build | |
DOSKEY jbb0=echo bundle exec jekyll build --baseurl="" ^& bundle exec jekyll build --baseurl="" | |
DOSKEY jb-epub=echo bundle exec jekyll build --config="_config.yml,_configs/_config.epub.yml" ^& bundle exec jekyll build --config="_config.yml,_configs/_config.epub.yml" | |
DOSKEY jsi-epub=echo bundle exec jekyll serve --incremental --config="_config.yml,_configs/_config.epub.yml" ^& bundle exec jekyll serve --incremental --config="_config.yml,_configs/_config.epub.yml" | |
DOSKEY jsi-print=echo bundle exec jekyll serve --incremental --config="_config.yml,_configs/_config.print-pdf.yml" ^& bundle exec jekyll serve --incremental --config="_config.yml,_configs/_config.print-pdf.yml" | |
DOSKEY js-live=echo bundle exec jekyll serve --config="_config.yml,_configs/_config.live.yml" ^& bundle exec jekyll serve --config="_config.yml,_configs/_config.live.yml" | |
:: Electric Book | |
DOSKEY rw=echo run-windows.bat ^& run-windows.bat | |
DOSKEY rwd=echo run-windows-default-output.bat ^& run-windows-default-output.bat | |
:: Do not use cls to clears screen when loaded. This will add a tofu line feed character | |
:: See https://stackoverflow.com/a/21389065/1781075 | |
:: Also, do not echo notes to your CLI from there. They will break some scripts | |
:: that read everything passed to the CLI. | |
:: VirtualBox | |
:: Open Ubuntu in a new virtual desktop | |
DOSKEY ubu=vdesk run:"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" startvm "Ubuntu-18.04" | |
:: Or on the same desktop | |
DOSKEY ubu1="C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" startvm "Ubuntu-18.04" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Command-line aliases
These files are my own, personal command-line aliases. Below I've left some instructions for setting them up. Note that you will almost certainly need to remove some of mine and add your own aliases! The ones here are specific to my environment, machines and preferences. Never use someone else's aliases unless you understand what they do.
Windows Command Prompt
The
DOSKEY
command sets an alias for a command in the Windows Command Prompt. This is a script ofDOSKEY
commands that set aliases I find useful. If you run it, it will set the aliases listed for the current command prompt, till you close it.If you want this script to load your aliases every time you open the command prompt, you need to tell Windows to autorun it whenever Command Prompt launches.
Warning: don't do this if you don't know what you're doing. Making mistakes when editing your registry can break your computer.
To do this in Windows 10:
C:\Users\USERNAME\AppData\Roaming
C:\WINDOWS\System32\regedt32.exe
)HKEY_CURRENT_USER\Software\Microsoft\Command Processor
AutoRun
for the Name.REG_SZ
for the Type."%AppData%\aliases.bat"
for the Data value.Each time you update
aliases.bat
, close and reopen the command prompt for the changes to take effect.Windows Bash
If you're using Windows Bash, copy the contents of
aliases.sh
to a.bash_profile
file in your user directory. The shortcut for getting to your user directory in the file explorer is to click on the file-path box, replace the contents with%USERPROFILE%
, and hit enter.In some setups using Git Bash in Windows, you may need
.bashrc
and an extra setup step.Ubuntu and OSX
Copy the contents of
aliases.sh
to a.bashrc
file in your home directory (i.e.~/.bashrc
). On OSX, this file is usually named.bash_profile
.