Skip to content

Instantly share code, notes, and snippets.

@mariocesar
Last active October 12, 2019 15:22
Show Gist options
  • Save mariocesar/1f92fda0f459dc85c71526384202b84e to your computer and use it in GitHub Desktop.
Save mariocesar/1f92fda0f459dc85c71526384202b84e to your computer and use it in GitHub Desktop.
Terminal one-liners, helpers and tricks. #docker #bash #terminal #python

Python

You have Python but not CURL or WGET installed, no problem

function urlget { \
    # urlget URL OUT \
    python -c "import urllib2;response=urllib2.urlopen('${1}');f=open('${2}', 'wb');f.write(response.read());f.close()" \
}

urlget http://ppa.launchpad.net/tabbott/zulip/ubuntu/pool/main/t/tsearch-extras/postgresql-9.5-tsearch-extras_0.2_amd64.deb tsearch-extras_0.2_amd64.deb
ls 
tsearch-extras_0.2_amd64.deb

Docker

Cleanup docker images, containers and volumes

echo container image volume | xargs -n1 -I% echo docker % prune -f

Tmux

Print all available color names that can be used to configure tmux

for i in {0..255} ; do
    printf "\x1b[38;5;${i}mcolour${i}\n"
done

Environment

Load environment variables from a file, take account comments, spaces and escaping. Using AWK

VAR1 = Hello
VAR2=Hello
# Comment

VAR3=Hello world
export $(awk -F= '/(.*)\s?=\s?(.*)/ { gsub(/ /, "", $1); gsub(/ /, "", $2); print ""$1"="$2;}' .envfile)
export VAR1=Hello VAR2=Hello VAR3='Hello world'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment