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
If you had the ear of a language creator, what would you say - what could they do to make a language that you would use? :upside_down_face:
New
AstonJ
In your opinion which programming languages are simple to use and easy to get started wither those who don’t have a computer science bac...
New
siddhant3030
I’m thinking of buying a monitor that I can rotate to use as a vertical monitor? Also, I want to know if someone is using it for program...
New
Exadra37
Cloudflare as workers to run serverless code without using containers: So it seems that Isolates is based on: What we ended up settl...
New
AstonJ
Great paper by Igor Kopestenski on Erlang and GRiSP: Erlang as an Enabling Technology for Resilient General-Purpose Applications on Edge ...
New
New
New
GermaVinsmoke
Do you like to help others on stackoverflow in your free time? And what’s your reputation on Stackoverflow? :smirk::joy::rofl:
New
chaptuck
I am thinking about getting a fitness tracker of some kind (probably one from Garmin). Have any of you developed your own widgets, watchf...
New
jaeyson
Hi!, hope everyone’s ok. Sorry if this question is ambiguous (i’ll remove this if i break some rules here). This is more like a self-ques...
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
Exadra37
I am thinking in building or buy a desktop computer for programing, both professionally and on my free time, and my choice of OS is Linux...
New
Exadra37
I am asking for any distro that only has the bare-bones to be able to get a shell in the server and then just install the packages as we ...
New
AstonJ
In case anyone else is wondering why Ruby 3 doesn’t show when you do asdf list-all ruby :man_facepalming: do this first: asdf plugin-upd...
New
rustkas
Intensively researching Erlang books and additional resources on it, I have found that the topic of using Regular Expressions is either c...
New
mafinar
This is going to be a long an frequently posted thread. While talking to a friend of mine who has taken data structure and algorithm cou...
New
First poster: bot
The overengineered Solution to my Pigeon Problem. TL;DR: I built a wifi-equipped water gun to shoot the pigeons on my balcony, controlle...
New
New
CommunityNews
A Brief Review of the Minisforum V3 AMD Tablet. Update: I have created an awesome-minisforum-v3 GitHub repository to list information fo...
New
AnfaengerAlex
Hello, I’m a beginner in Android development and I’m facing an issue with my project setup. In my build.gradle.kts file, I have the foll...
New