Twitter (not set)
Blog (not set)
Website (not set)

0

Search man pages and present a PDF

 $ man -k . | awk '{ print $1 " " $2 }' | dmenu -i -p man | awk '{ print $2 " " $1 }' | tr -d '()' | xargs man -t | ps2pdf - - | zathura -

— by Jab2870 on Dec. 18, 2018, 11:31 a.m.

Explanation

This uses dmenu to search through your man pages then produces a pdf for the one you selected

  1. man -k . lists all man pages
  2. awk '{ print $1 " " $2 }' prints the first column, a space then the second column
    • This results in lines like this: curl (1)
  3. dmenu -i -p man takes a list fron stdin and lets you choose one. It returns what you chose
    • You can swap dmenu for somethign like rofi if required
  4. awk '{ print $2 " " $1 }' puts the second column first
    • The output is now like (1) curl
  5. tr -d '()' removes the brackets
  6. xargs man -t puts the result at the end of the command man -t
    • This makes the command something like man -t 1 curl
    • the -t flag makes man use troff to format the page
  7. ps2pdf - - produces a PDF from the postscritpt output by the previous command
  8. zathura - is a pdf reafer that can read STDIN

Limitations

You will need a PDF viewer that can read from STDIN

You will need ps2pdf installed which is part of ghostscript

You will need dmenu or a dmenu compatible program installed.

Almost all systems will already have xargs, tr troff, awk installed.

0

Organise image by portrait and landscape

 $ mkdir "portraits"; mkdir "landscapes"; for f in ./*.jpg; do WIDTH=$(identify -format "%w" "$f")> /dev/null; HEIGHT=$(identify -format "%h" "$f")> /dev/null; if [[ "$HEIGHT" > "$WIDTH" ]]; then mv "$f" portraits/ ; else mv "$f" landscapes/ ; fi; done

— by Jab2870 on Aug. 23, 2018, 2:09 p.m.

Explanation

  1. First makes directory for portraits and landscapes
  2. Loops through all files in the current directory with the extention .jpg, feel free to change this to .png or .jpeg if neccesary
    1. Gets the width and height for the current image using the identify command
    2. If height > width, move it to Portarits folder, otherwise move it to landscapes

Limitations

This relies on the identify command which comes with ImageMagick which is available on most systems.

This does not check for square images, although it could be easily extended to see if HEIGHT and WIDTH are equal. Square images are currently put with the landscape images.

2

Random Git Commit

 $ git commit -m "$(w3m whatthecommit.com | head -n 1)"

— by Jab2870 on Jan. 5, 2018, 4:55 p.m.

Explanation

This will commit a message pulled from What the Commit.

-m allows you to provide the commit message without entering your editor

w3m is a terminal based web browser. We basically use it to strip out all of the html tags

head -n 1 will grab only the first line

Limitations

This requires you to have w3m installed

1

Get the latest Arch Linux news

 $ w3m https://www.archlinux.org/ | sed -n "/Latest News/,/Older News/p" | head -n -1

— by Jab2870 on Aug. 15, 2017, 10:35 a.m.

Explanation

w3m is a terminal web browser. We use it to go to https://www.archlinux.org/

We then use sed to capture the text between Latest News and Older News.

We then get rid of the last line which is Older News.

Limitations

For this, w3m would need to be installed. It should be installable on most systems.

If Arch change the format of there website significantly, this might stop working.

1

Listen to the radio (radio2 in example)

 $ mpv http://a.files.bbci.co.uk/media/live/manifesto/audio/simulcast/hls/uk/sbr_med/llnw/bbc_radio_two.m3u8

— by Jab2870 on July 19, 2017, 2:44 p.m.

Explanation

MPV is a terminal audio player. You could also use vlc or any media player that supports streams.

To find a stream for your favourite uk radio station, look here: UK Audio Streams. If you are outside of the uk, Google is your friend

Limitations

Requires an audio player that supports streams.

1

Go up to a particular folder

 $ alias ph='cd ${PWD%/public_html*}/public_html'

— by Jab2870 on July 18, 2017, 6:07 p.m.

Explanation

I work on a lot of websites and often need to go up to the public_html folder.

This command creates an alias so that however many folders deep I am, I will be taken up to the correct folder.

alias ph='....': This creates a shortcut so that when command ph is typed, the part between the quotes is executed

cd ...: This changes directory to the directory specified

PWD: This is a global bash variable that contains the current directory

${...%/public_html*}: This removes /public_html and anything after it from the specified string

Finally, /public_html at the end is appended onto the string.

So, to sum up, when ph is run, we ask bash to change the directory to the current working directory with anything after public_html removed.

Examples

If I am in the directory ~/Sites/site1/public_html/test/blog/ I will be taken to ~/Sites/site1/public_html/

If I am in the directory ~/Sites/site2/public_html/test/sources/javascript/es6/ I will be taken to ~/Sites/site2/public_html/

3

Open another terminal at current location

 $ $TERMINAL & disown

— by Jab2870 on July 18, 2017, 3:04 p.m.

Explanation

Opens another terminal window at the current location.

Use Case

I often cd into a directory and decide it would be useful to open another terminal in the same folder, maybe for an editor or something. Previously, I would open the terminal and repeat the CD command.

I have aliased this command to open so I just type open and I get a new terminal already in my desired folder.

The & disown part of the command stops the new terminal from being dependant on the first meaning that you can still use the first and if you close the first, the second will remain open.

Limitations

It relied on you having the $TERMINAL global variable set. If you don't have this set you could easily change it to something like the following:

gnome-terminal & disown or konsole & disown

0

Corporate random bullshit generator (cbsg)

 $ curl -s http://cbsg.sourceforge.net/cgi-bin/live | grep -Eo '^<li>.*</li>' | sed s,\</\\?li\>,,g | shuf -n 1 | cowsay

— by Jab2870 on June 7, 2017, 4:11 p.m.

Explanation

Lets make a cow talk BS

Limitations

I don't think cowsay is installed by default on a mac although it can be installed with brew cowsay