Julien Palard

Python Developer and Trainer

How I use bash

bash

I presented this as a lightnign talk at « En attendant la PyCon Fr », there's a video (in french).

How to read:

When I write ^A it mean I press Ctrl-A, which is noted C-a (bash/emacs notation).

M-a means Meta-a (it's left alt on current keyboards).

I avoid singleline prompt

Because of the following issue:

PS1='$ '
printf "pouette"
ls^A
ls -l^A

Issue is: readline have two ways to move at the beginning of a line, and have no way to know where the cursor is, and assume the line start at column 0.

Easy, daily, shortcuts

Killing and Yanking from the killing stack

Example:

$ git push origin HEAD^A^Kgit commit -m "FIX"^A^Kgit add -u
C-y
Enter
C-y
M-y
Enter

Moving

Avoid C-pC-pC-pC-pC-p or ↑↑↑↑↑↑, use C-r.

Fixing typos

Cleaning

C-l (clear screen). Oh, if it's not enough, like after killing sl, use reset, so ENTER reset ENTER to ensure you type it in a clear line, or C-a C-k reset ENTER to avoid executing blindly.

sudo !!

$ man bash | grep '!!'
!!     Refer to the previous command.  This is a synonym for `!-1'.

so:

$ apt upgrade
E: ... are you root?
$ sudo !!
sudo apt upgrade
...

Globstar

shopt -s globstar:

$ rm **/*.md

same as:

$ find -name '*.md' -delete

example:

sed -i '1i#!/usr/bin/env python3' **/*.py

Other shortcuts I use

And I like them for the nice symetry:

Pipelines for the win!

$ man bash | grep -C1 C-a
Commands for Moving
    beginning-of-line (C-a)
        Move to the start of the current line.

Subshells for the win!

emacs $(git grep -l PATTERN)

Bonus

Those are the same in emacs, save brain space, use emacs.