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
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
dasdom
No chair. I have a standing desk. This post was split into a dedicated thread from our thread about chairs :slight_smile:
New
AstonJ
Just been adding some more portals, currently have the following languages: Apache Groovy C C# C++ Clojure CoffeeScript Crystal ...
New
DevotionGeo
As the title suggests, this thread will contain some real wisdom came from experience. Please add something meaningful than fancy looking...
New
AstonJ
Great paper by Igor Kopestenski on Erlang and GRiSP: Erlang as an Enabling Technology for Resilient General-Purpose Applications on Edge ...
New
Rainer
Not sure if following fits exactly this thread, or if we should have a hobby thread… For many years I’m designing and building model air...
New
AstonJ
Hi everyone… I’m so sorry about the delay in getting this thread up, I’ve just been so busy :see_no_evil: Are there any book clubs you’d...
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
DevotionGeo
For me it’s six to seven steps above complete dark, on MacBook Air M1.
New
harwind
I’m working on a C++ program where I need to convert a string containing a numeric value into an integer. I want to ensure that this conv...
New

Other popular topics Top

Devtalk
Hello Devtalk World! Please let us know a little about who you are and where you’re from :nerd_face:
New
AstonJ
If it’s a mechanical keyboard, which switches do you have? Would you recommend it? Why? What will your next keyboard be? Pics always w...
New
AstonJ
What chair do you have while working… and why? Is there a ‘best’ type of chair or working position for developers?
New
ohm
Which, if any, games do you play? On what platform? I just bought (and completed) Minecraft Dungeons for my Nintendo Switch. Other than ...
New
AstonJ
SpaceVim seems to be gaining in features and popularity and I just wondered how it compares with SpaceMacs in 2020 - anyone have any thou...
New
PragmaticBookshelf
Build highly interactive applications without ever leaving Elixir, the way the experts do. Let LiveView take care of performance, scalabi...
New
AstonJ
If you get Can't find emacs in your PATH when trying to install Doom Emacs on your Mac you… just… need to install Emacs first! :lol: bre...
New
PragmaticBookshelf
Author Spotlight Jamis Buck @jamis This month, we have the pleasure of spotlighting author Jamis Buck, who has written Mazes for Prog...
New
PragmaticBookshelf
Author Spotlight Rebecca Skinner @RebeccaSkinner Welcome to our latest author spotlight, where we sit down with Rebecca Skinner, auth...
New
hilfordjames
There appears to have been an update that has changed the terminology for what has previously been known as the Taskbar Overflow - this h...
New