Share your command line shortcuts, aliases, profiles, etc

Hey Devs! :wave:

About a month ago, I got a new machine (MAC) and am in the process of setting up/revising my command line shortcuts. I know a lot of this will vary, based on the work/technologies you use on the daily basis, but are there any shortcuts, aliases, etc. that you couldn’t live without or have made your life easier?

Side Note:
For those who are new or interested in stepping up there terminal game, I use Hyper for my terminal and Oh My Zsh for it’s magic. Here is a decent article covering basic aliases, etc for getting started.

2 Likes
PS1="[\W]\$ "
alias ll="ls -lahG"

alias code="cd /Users/Aston/projects/code"
alias home="cd /Users/Aston"
alias oss="cd /Users/Aston/projects/oss"
alias desktop="cd /Users/Aston/desktop"
alias some_project_name="cd /Users/Aston/projects/code/some_project_name"

alias reload=". ~/.zshrc"
alias profile="mate ~/.zshrc"
alias p="profile"

SERVER_ONE="IP.HERE"
SERVER_TWO="IP.HERE"
SERVER_THREE="IP.HERE"
(etc)

alias server_name="ssh root@$SERVER_ONE -p <PORT-NUM>"

alias showhidden="defaults write com.apple.finder AppleShowAllFiles -boolean true ; killall Finder"
alias hidehidden="defaults write com.apple.finder AppleShowAllFiles -boolean false ; killall Finder"
alias screengrab-jpg="defaults write com.apple.screencapture type jpg"
alias screengrab-png="defaults write com.apple.screencapture type png"
alias websharing="sudo launchctl load -w /System/Library/LaunchDaemons/org.apache.httpd.plist"
alias websharingoff="sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist"

function gitinit {
	git init
	git add --all
	git commit -m ${1:-"Init repo"}
}

I also have some commands that push various updates and even deploy some Rails apps (instead of using something like Capistrano) :smiley:

2 Likes

My aliases are pretty boring but I’d recommend you a few newer tools to make your way around the console much easier.

Suppose you want to quickly scan the directory you are in for a textual pattern, regardless of which file it is in. You’ll need the Rust stack, then skim and ripgrep (or the silver searcher) and then you can make an alias like this:

# If you want to use ripgrep:
alias skrg='sk --ansi -i -c "rg --color=always --line-number --ignore-case {}"'

# If you want to use the silver searcher:
alias skag='sk --ansi -i -c "ag --color {}"'

Then you get inside a project’s directory, type one of the both commands (skrg or skag) and you literally start typing the pattern you want found in any of the source files – you get instantaneous realtime feedback as you go. You can select one or many files and when you quit the tool it will output all selected files – so if you don’t want to only eyeball the results but actually feed them to another tool you can just pipe the command to something else.

This is of course a regular feature for IDEs but since I don’t use VSCode – and I still haven’t installed Spacemacs – these make my life easier.

ripgrep itself I use for several months now and I absolutely prefer it compared to grep.

I also replaced GNU/BSD’s find with Rust’s fd and I am very happy with it.

I use several other Rust tools but this comment will get way too big.

3 Likes

Thanks guys!

@AstonJ, mine are pretty similar.

@dimitarvp mine are pretty boring too. I just thought this could be a cool topic and I’m sure someone will end up sharing some cool nuggets. I’ll have to look into ripgrep, haven’t seen that one before.

2 Likes

My .zshrc file is utterly huge. I also use OMZ but I’ve added so much stuff to my rc file, especially aliases, that I’ve found useful over time, though a lot have personal things in them so I’d have to go over each to make sure it’s “safe” to post, plus I have so many it’s easier to pick out things that do specific things as wanted for others. ^.^;

Here are some of my most used ones though but significantly not all:

alias digall='dig +nocmd any +multiline +noall +answer'

alias git-pristine='git clean --force -xd && git reset --hard'

alias diff-color='git diff --no-index'
alias diff-char='git diff --word-diff=color --word-diff-regex=. --no-index'
function diff-factorio-binary() {
        [[ -z "$1" ]] && echo "Missing first argument of <left-file>" && exit 1
        [[ -z "$2" ]] && echo "Missing second argument of <right-file>" && exit 2
        [[ -z "$3" ]] || echo "Too many arguments, ignoreing all but first two"
        #colordiff <(tr -c '[:print:]' '\n' < "$1" | tr "\\>" ">\n" | tr "," ",\n") <(tr -c '[:print:]' '\n' < "$2" | tr "\\>" ">\n" | tr "," ",\n")
        colordiff <(python -c 'import sys;print(repr(open(sys.argv[1]).read().replace(",", ",\n").replace(">", ">\n")).replace("\\n", "\n"))' "$1") \
                  <(python -c 'import sys;print(repr(open(sys.argv[1]).read().replace(",", ",\n").replace(">", ">\n")).replace("\\n", "\n"))' "$2")
}

alias emax='emacsclient -c' # Open in new X-Windows
alias emat='emacsclient -t' # Open in current terminal
alias emacs-stop='systemctl --user stop emacs.service'
alias emacs-start='systemctl --user start emacs.service'
#alias emacs-restart='systemctl --user restart emacs.service' # It's not setup for a restart command
export VISUAL='emacsclient -c'
export EDITOR='emacsclient -t'
alias weather='curl wttr.in'
# Can also specify location specifically, it uses IP address by default:
# alias weather='curl wttr.in/Longdon'
# Or ask for help:  curl wttr.in/:help
# Single-line output:
alias weathr='curl wttr.in/?format="%l:+%c+%t+%h+%m%M"'


ix() {
    local opts
    local OPTIND
    [ -f "$HOME/.netrc" ] && opts='-n'
    while getopts ":hd:i:n:" x; do
        case $x in
            h) echo "ix [-d ID] [-i ID] [-n N] [opts]"; return;;
            d) $echo curl $opts -X DELETE ix.io/$OPTARG; return;;
            i) opts="$opts -X PUT"; local id="$OPTARG";; 
            n) opts="$opts -F read:1=$OPTARG";;
        esac
    done
    shift $(($OPTIND - 1))
    [ -t 0 ] && {
        local filename="$1"
        shift 
        [ "$filename" ] && {
            curl $opts -F f:1=@"$filename" $* ix.io/$id
            return
        }   
        echo "^C to cancel, ^D to send."
    }   
    curl $opts -F f:1='<-' $* ix.io/$id
}
3 Likes