DEV Community

Lazy habits in linux terminal

Paula on November 30, 2017

We all look like hackers when using the terminal (specially if we have green over black theme) but the truth is we tend to be amazingly lazy, and...
Collapse
 
val_baca profile image
Valentin Baca

These don't sound lazy at all, but just properly following the path of least resistance.

Though it sounds like some of these (like the cd example) could be simplified with Tab-completion.

I really hated copying and pasting or typing out individual filenames with git, so I started using github.com/holygeek/git-number which gives the ease of a git gui to the git cli.

My motto for shortcuts and aliases is that "I just hate typing" even though I really don't, but it forces me to think "how many times do I do this?" what if I cut the command in half?

Collapse
 
jj profile image
Juan Julián Merelo Guervós

I never get to write aliases for git * which I use every single day. I should do it now.

Collapse
 
martyonthefly profile image
Sylvain Marty • Edited

I hate using rmdir and I always write rm -rf because it happens that I need to remove multiple files and directories at once and I'm to lazy to write multiple commands :(

Thanks for sharing, I love this kind of content! :)

Collapse
 
itsjzt profile image
Saurabh Sharma

I like to use trash, It's a lot better tool. check it out! npmjs.com/package/trash-cli

Collapse
 
martyonthefly profile image
Sylvain Marty

Thanks, I'll give it a try ! :)

Thread Thread
 
itsjzt profile image
Saurabh Sharma

but don't forget to make alias, so you get trash when typing rm

Thread Thread
 
legolord208 profile image
jD91mZM2

That's a bad idea, scripts might use rm and it starts adding up to your trash. Also, if you keep the habit of using rm you might be less careful when using it on a machine that doesn't have trash installed.

Solution: For now, make rm print something like "no, use trash", and get a habit of using trash over rm.

Thread Thread
 
martyonthefly profile image
Sylvain Marty

Good observation!

In fact, I don't think I'll continue to use trash because it's relatively slow compared to rm. Finally, it's a part of my job to think before acting ¯_(ツ)_/¯.

Thread Thread
 
legolord208 profile image
jD91mZM2

No no no that's not what I meant! Even if I barely ever need to restore from trash, it's really nice to not feel worried you're destroying your system. Also, shouldn't moving directories be faster than deleting each file?

Thread Thread
 
martyonthefly profile image
Sylvain Marty

I'm guessing NodeJS fs is not as fast as the linux filesystem ? ^

Thread Thread
 
legolord208 profile image
jD91mZM2

You were using a NodeJS version of trash-cli? Try github.com/andreafrancia/trash-cli.

Thread Thread
 
martyonthefly profile image
Sylvain Marty

I tried the version mentioned earlier:
github.com/sindresorhus/trash-cli

I'll give a try to yours :)

Thread Thread
 
legolord208 profile image
jD91mZM2

Always choose the first result on Google ;)

Collapse
 
terceranexus6 profile image
Paula

I do the same!! Oh my..

Collapse
 
kayis profile image
K

Hm... I guess mine would be stuff like git amend after git push, also git push --force :D

Collapse
 
papey profile image
Jean Michel Functional Programming

Aliases for lazy people :

# - Alias
# ls
alias ls='exa'
alias ll='exa -l'
alias lll='exa -l | less'
alias lla='exa -la'
alias llt='exa -T'
alias llfu='exa -bghHliS --git'

# cp
alias cp='cp -R'

# scp
alias scp='scp -r'
alias grep='grep --color=auto'

# ça pipe
alias -g G='| grep'
alias -g L='| less'
alias -g M='| most'
alias -g NE='2> /dev/null'
alias -g NUL='> /dev/null 2>&1'
alias -g S='| sort'
alias -g T='tail -f'
alias -g W='| wc -l'

# cd
alias ..='cd ..'
alias s='cd ..'
alias d='cd -'

# mkdir
alias mkdir='mkdir -p'

# df
alias df='df -kTh'

# vi
alias vi='nvim'
alias vim='nvim'

# Compression
alias jtetar='tar -cvf'
alias jtedtar='tar -xvf'

# git
alias g='git'

# pacman
alias pacsy='sudo pacman -Sy'
alias pacsyu='sudo pacman -Syu'
alias pacsu='sudo pacman -Su'
alias pacr='sudo pacman -Rcs'

# ping
alias ping='ping -c 3'

# task
alias t='task'

# sudo
alias s='sudo '
alias se='sudoedit'

# systemd
alias sctl='systemctl'
alias jctl='journalctl'

# docker
alias dm='docker-machine'
alias d='docker'
alias dc='docker-compose'

# ansible
alias ap='ansible-playbook'

Git aliases for super lazy people :

[alias]
    lg = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --
    ac =  !git add . && git commit -am
    a = add
    ap = add -p
    co = checkout
    cob = checkout -b
    d = diff
    pr = pull --rebase
    dc = diff --cached
    cv = commit --verbose
    ci = commit
    cam = commit -am
    s = status -s
    br = branch
    hist = log --pretty=format:\"%Cred%h%Creset - %C(blue)%ad%Creset %Cgreen→%Creset %s%C(yellow)%d%Creset %C(magenta)[%an]%Creset\" --graph --date=short
    unst = reset HEAD
    la = "!git config -l | grep alias | cut -c 7-"

With a lazy alias to show other lazy aliases (la)

Collapse
 
ioayman profile image
Ayman Nedjmeddine

Sometimes I need to just type something into the clipboard (sometimes to avoid memorizing it!), so this one comes handy for me often

alias writeinclipboard='[[ -x `which xclip 2>/dev/null` ]] && cat << EOF | xclip -selection clipboard '
Collapse
 
mlv profile image
Michael Vezie

For me, it's stopped jobs. It's rare that, in a window where I'm actively working, I don't have less than 6 stopped jobs (at least 2-3 ipython shells, lessing some file, maybe a man page or two). In some cases, I've had over 20.

I had the same tmux session on this one machine for at least two years, then recently it just died (of old age, I presume). I was devastated.

Collapse
 
andy profile image
Andy Zhao (he/him)

I constantly git stash and completely forget what I stashed, then just end up running git stash clear anyway and rewrite whatever I was doing.

Definitely have had times where I had more than 7 stashes saved though...

Collapse
 
mangekalpesh profile image
Kalpesh Mange • Edited


git stash

is bae <3 ;)

Collapse
 
bgalvao profile image
Bernardo

Some .bash_aliases that I forget to use all the time haha. Plus, I have a folder named github to git clone all the things, and a folder repos for my projects that I leave halfway (that's sad now that I think about it :'().

Collapse
 
wipsdafox profile image
wips

I made a script for committing to GitHub because I am too lazy to commit normally.

Collapse
 
codemouse92 profile image
Jason C. McDonald

Wait, I'm not supposed to use git add .? Usually, I want all the changes I made in the directory to get committed.

Collapse
 
jj profile image
Juan Julián Merelo Guervós

It's not a good idea. You could add generated files, backups, and conf files with stuff you don't want added. It's better to use (small) trump cards like *.png or simply add file by file. You don't need to use git add every time you commit, git commit -am "message" will add to the commit everything that has been modified.

Collapse
 
ben profile image
Ben Halpern

You could, but I typically have a command line + visualization set up and in most cases, I go with git add . and go through the verification step visually beforehand.

Collapse
 
codemouse92 profile image
Jason C. McDonald • Edited

Well, I don't know. Your .gitignore really needs to be configured correctly, as a rule. I haven't added a wrong file in three years.

Thread Thread
 
kayis profile image
K

I always use git add -p solved the problem for me too

Thread Thread
 
jj profile image
Juan Julián Merelo Guervós

Well, I don't know. You might have some secret information in a .json or in a .yml file. You might exclude it by name in .gitignore, but then you would have to remember to do so. Routinely doing individual (or pattern inside a directory) is a better practice where you don't have to remember to add every possible file with non-public information to .gitignore.

Thread Thread
 
codemouse92 profile image
Jason C. McDonald • Edited

Well, first of all, .gitignore is smarter than that. You can exclude using patterns and directories, the same as you can do for git add.

Second, in most cases, you shouldn't be putting secret information in the repository to begin with. Use a separate directory.

Third, think about the mind-memory load you're talking about here. Either you remember all the files with non-public information once and add it to a file (.gitignore), or you remember all the files period and discriminate which to add every single time (git add). You're having to remember what not to add ANYWAY. If you can use a mental shortcut like "Well, I never change .yaml", then you should be adding *.yaml to .gitignore. Work smarter, not harder.

In the end, it may depend on the project. I have never worked on a project where manually using git add instead of .gitignore was worth the tremendous expenditure of effort. There may be exceptions.

Ultimately, remember that Git offers both features because one size doesn't fit all.

Collapse
 
dmfay profile image
Dian Fay • Edited

I only have a few aliases I use with any regularity and most of them are less laziness and more not wanting to remember byzantine argument and switch combinations for specific tasks:

listening='netstat -plnt'
vpn='cd /etc/openvpn && sudo openvpn --config /etc/openvpn/vpn.conf'
rot13='tr a-zA-Z n-za-mN-ZA-M'
gunm='echo -e "$(git ls-files --modified)\n$(git ls-files)" | sort | uniq -u'
gtree='git log --graph --abbrev-commit --decorate --date=relative --format=format:'\''%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)'\'' --all'
Collapse
 
garthvador profile image
Quentin Caillaud • Edited

Back when I discovered the splendor of aliases, I went a little too far and used to have the following alias in my bash_aliases...

alias g='git'

But then, using it, I realized that it was a little too much. (and auto completion with tab for git was unavailable this way, so too much laziness was killing laziness ! ;) )

Collapse
 
svedi profile image
Sven

I often use the arrows to find some complex command that I used a week ago. While doing so I usually realize that I would have already found it if I had used the search with Ctrl+R. And it only got worse since I switched from bash to zsh! :)

Collapse
 
dsanchezseco profile image
dsanchezseco

The old but gold alias ll='ls -lah'

Collapse
 
voyeg3r profile image
Sérgio Araújo • Edited

Using fasd cd, zsh-autosuggestions and zsh-autopair helped me a lot with complicated paths/commands. A bunch of aliases also helps me a lot, for example, open the last edited file.

 alias lnvim='nvim -c'\'':e#<1'\'

Dealing with clipboard:

alias pbcopy='xclip -selection clipboard'
alias pbpaste='xclip -i -selection clipboard -o'

Some useful functions like:

# Goes to the folder or create it and goes anyway
mkcd () {
    mkdir -pv -p "$@" && cd $_
}

Does a lazy git commit:

gsend () {
    git commit -am "$1" && git push
}
Collapse
 
dieg0la profile image
DiegoGo

I use fish shell to autocomplete commands

Collapse
 
m1well profile image
Michael Wellner

To be very lazy, i have my own cheatsheet to display my most important commands AND also with an execution functionality. github.com/m1well/cheatsheet

Collapse
 
komasoftware profile image
Koen

I always do CTRL+r before I start typing anything in the command line to match my history of commands..

Collapse
 
mikeralphson profile image
Mike Ralphson

alias cd..='cd ..' saves me hours.

Collapse
 
pmcgowan profile image
p-mcgowan

I have
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'
I dont usually use the last one though

Collapse
 
awkravchuk profile image
Andrew Kravchuk • Edited

I plead guilty (-_-)

Collapse
 
carywreams profile image
Cary Reams

lazy != bad;

I keep a ~/wormholes directory for soft links to buried, frequently used directories, enabling

cd ~/wormholes/repo-1

Collapse
 
enzoftware profile image
Enzo Lizama Paredes • Edited

I dont know if that its lazy habits but i code an automation tool for push code into github , with git add . 😂😂😂 . But its less work for me. Greets!!

Collapse
 
heshamaboelmagd profile image
Hesham Abo El-Magd

Aliases.. Lots of 'em

Collapse
 
rogerzanoni profile image
Roger Zanoni

I think git aliases from oh-my-zsh git plugin are made for and by lazy people <3

github.com/robbyrussell/oh-my-zsh/...