justinjunodev

justinjunodev

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.

Most Liked

dimitarvp

dimitarvp

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.

OvermindDL1

OvermindDL1

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
}
AstonJ

AstonJ

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:

Popular General Dev topics Top

KyleHunter
What is a good language for beginners to make apps like snapchat and instagram?
New
andresriveros
I am currently subscribed to: The Ruby Rogues Remote Ruby Maintainable Planet Argon founder and ohmyzsh creator. https://maintainab...
New
Rainer
Have you seen the new features that will be available in the upcoming C# 9 release? C# is taking a lot of input from functional l...
New
New
AstonJ
Are you a touch typist? :keyboard: poll If you haven’t checked your typing speed yet, you can do so here here :smiley:
New
New
OvermindDL1
What shell(s) do you use, why do you use them, and how do you have them configured? Note, this is about shell’s, not terminals, terminal...
New
DevotionGeo
I hate having mandatory semicolons in a language, no matter how beautiful the language is otherwise. What about you?
New
Margaret
Hello everyone! This thread is to tell you about what authors from The Pragmatic Bookshelf are writing on Medium.
1139 25467 754
New
AstonJ
Chris Seaton, the creator of TruffleRuby has died. It appears from suicide :cry: He left this note on Twitter on the weekend: And one...
New

Other popular topics Top

AstonJ
What chair do you have while working… and why? Is there a ‘best’ type of chair or working position for developers?
New
AstonJ
Or looking forward to? :nerd_face:
New
Exadra37
Please tell us what is your preferred monitor setup for programming(not gaming) and why you have chosen it. Does your monitor have eye p...
New
PragmaticBookshelf
Design and develop sophisticated 2D games that are as much fun to make as they are to play. From particle effects and pathfinding to soci...
New
AstonJ
There’s a whole world of custom keycaps out there that I didn’t know existed! Check out all of our Keycaps threads here: https://forum....
New
AstonJ
I have seen the keycaps I want - they are due for a group-buy this week but won’t be delivered until October next year!!! :rofl: The Ser...
New
AstonJ
Continuing the discussion from Thinking about learning Crystal, let’s discuss - I was wondering which languages don’t GC - maybe we can c...
New
PragmaticBookshelf
Rails 7 completely redefines what it means to produce fantastic user experiences and provides a way to achieve all the benefits of single...
New
AstonJ
If you want a quick and easy way to block any website on your Mac using Little Snitch simply… File &gt; New Rule: And select Deny, O...
New
First poster: bot
Large Language Models like ChatGPT say The Darnedest Things. The Errors They MakeWhy We Need to Document Them, and What We Have Decided ...
New