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:

Where Next?

Popular General Dev topics Top

AstonJ
Which apps do you think are killing it right now? Either from a technical perspective or ones that you like personally or feel have been...
New
AstonJ
Looking at @siddhant3030’s photo from the Do you blog? thread, do you cover your computer or phone camera as a security precaution? Wha...
New
AstonJ
Just been adding some more portals, currently have the following languages: Apache Groovy C C# C++ Clojure CoffeeScript Crystal ...
New
New
Exadra37
I am a Linux user since 2012, more or less, and I always use Ubuntu on my computers, and my last 2 laptops have been used Thinkpads, wher...
New
New
AstonJ
Things like smart speakers (such Amazon Alexa), smart TVs or other devices with built in microphones, cameras or with other features that...
New
ohm
I just switched jobs to tech lead with a small team of about 6 other developer. This is my first tech lead job. What do I need to know? A...
New
AstonJ
00:00 The Year 2022 00:38 Web3 03:28 Metaverse 05:05 AI 06:22 Databases 07:31 JavaScript 09:58 Other Trends to Know WDYT - what wi...
New
AstonJ
I’ve been watching Prag Dave’s Elixir course and I noticed he uses tree: Tree is a recursive directory listing program that produces a ...
New

Other popular topics Top

AstonJ
Thanks to @foxtrottwist’s and @Tomas’s posts in this thread: Poll: Which code editor do you use? I bought Onivim! :nerd_face: https://on...
New
AstonJ
Just done a fresh install of macOS Big Sur and on installing Erlang I am getting: asdf install erlang 23.1.2 Configure failed. checking ...
New
PragmaticBookshelf
Learn different ways of writing concurrent code in Elixir and increase your application's performance, without sacrificing scalability or...
New
PragmaticBookshelf
“A Mystical Experience” Hero’s Journey with Paolo Perrotta @nusco Ever wonder how authoring books compares to writing articles?...
New
New
Margaret
Hello everyone! This thread is to tell you about what authors from The Pragmatic Bookshelf are writing on Medium.
1143 25883 760
New
wmnnd
Here’s the story how one of the world’s first production deployments of LiveView came to be - and how trying to improve it almost caused ...
New
gagan7995
API 4 Path: /user/following/ Method: GET Description: Returns the list of all names of people whom the user follows Response [ { ...
New
foxtrottwist
A few weeks ago I started using Warp a terminal written in rust. Though in it’s current state of development there are a few caveats (tab...
New
AstonJ
If you’re getting errors like this: psql: error: connection to server on socket “/tmp/.s.PGSQL.5432” failed: No such file or directory ...
New