filter:   bash ×
Tuesday, January 27th, 2026 bash utils • 91w

Are you bored of typing ls all the time in your terminal. Wouldn't be greate if you could just hit a shortcut? You are in luck, because you just can. No addon, no nothing, just with the built-in bind:

bind '"\el":"ls -thor\n"'

Here you just bind Alt-L to run ls -thor.



done_

Sunday, February 7th, 2021 bash code easy utils • 182w

Ok, lets create a single line of bash that will handle the -h option and print something.

First, what to print? I usually add some comments on the start of the file, so lets print that. Example script:

#!/bin/bash
#
#  This is the doc of the script
#

the line that we will add

code of script

Lets go step by step. We need to print the file it self:

cat "$0"

Skip the first line (lets switch to sed):

sed -n '2,$ p' "$0"

Go until you find the first empty line:

sed -n '2,/^$/ p' "$0"

Remove the # fro the start of the line:

sed '2,/^$/ s/#// p' "$0"

Finally, we check if the -h is the first argument, print the thing and exit:

[ "$1" = '-h' ] && sed -n '2,/^$/ s/#// p' "$0" && exit



done_