This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# https://github.com/estysdesu/dotFiles/blob/master/bin/tmuxColour | |
for i in {0..255}; do | |
printf "\x1b[38;5;${i}mcolour${i}\x1b[0m\n" | |
done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##### if, elif, else, fi (CONDITIONAL) ##### | |
# https://www.netacad.com/courses/os-it/ndg-linux-essentials --> Ch11: Basic Scripting | |
if [ "$1" = "hello" ]; then # square brackets are same as test command `test "$1" = "hello"` | |
echo "hello yourself" | |
elif [ "$1" = "goodbye" ]; then | |
echo "nice to have met you" | |
echo "I hope to see you again" | |
else | |
echo "I didn't understand that" | |
fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##### REGEX CHARACTERS/GLOBS ##### | |
. # match any one single character | |
* # match the previous character repeated 0+ times | |
? # match the previous character repeated 0 or 1 time (extended pattern `-E`) | |
+ # match the previous character repeated 1+ times (extended pattern `-E`) | |
{<num>} # match the previous character repeated the number of times specificed in the braces (extended pattern `-E`) | |
[<chars>] # character range to match one time; check `ascii` | |
[^<chars>] # character range to not match one time; check `ascii` | |
^ # if first char of pattern, pattern must be at start of line to match | |
$ # if last char of pattern, pattern must be at end of line to match |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##### tr (TRANSLATE/DELETE) ##### | |
# tr <pattern-translate-in> <pattern-translate-out> | |
# -d: delete SET1 | |
# -t: truncate SET1 to length of SET2 | |
# -c: compliment SET1 | |
# -s: squeeze the repitition SET1 | |
tr 'a-z' 'A-Z' < <file> # converts input to all caps | |
tr -d ' ' < <file># delete spaces | |
cat <file> | tr -cd [:digit:] # delete all but digits |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##### cat (SHOW ALL FILE CONTENTS) ##### | |
cat <file> # shows all file contents | |
cat <enter>...<ctrl+d> # echos whatever is typed after enter (useful for redirecting stdin) | |
##### less/more (PAGERS) ##### | |
less <file> # more advanced version of `more`; allows vim navigation | |
##### head/tail (PARTIAL CONTENTS) ##### | |
# Normal indexing (GNU/UNIX) | |
head -n 5 <file> # first 5 lines (defaults to 10) == `head -5 <file>` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##### tar (ARCHIVING) ##### | |
# -z: gzip | |
# -j: bzip2 | |
# -J: xz | |
# if compression method is missing, tar tries to guess compression method (from extension) | |
# -c: create | |
# -x: extract | |
# -v: verbose (list each file) | |
# -f: archive file name | |
# -r: append to unzipped archive |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://effbot.org/zone/python-with-statement.htm | |
class Tyler(): | |
def __enter__(self): | |
# <set-up> | |
# return <something> # essentially "with this state thats returned, do something" | |
def __exit__(self): | |
# <tear-down> | |
with Tyler() as ty: | |
# <do-something-with-ty> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##### test OR [ -s/-n/-t/(etc...) ] (TEST CONDITIONALS) ##### | |
# https://www.gnu.org/software/bash/manual/html_node/Bash-Conditional-Expressions.html | |
# numeric and string are different for numbers -- `test 01 -eq 1` is true, but `test "01" == "1"` is obviously not | |
# -f: file exists | |
# -s: file exists and has size > 0 | |
# ! <-flag>: negate | |
# -d: directory exists | |
# -x: can execute | |
# <#> -eq <#>: numeric equality; good for exit codes | |
# <#> -ne <#>: numeric inequality (test if not equal) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://thoughtbot.com/blog/input-output-redirection-in-the-shell | |
# http://mywiki.wooledge.org/BashSheet#Streams | |
# http://www.learnlinux.org.za/courses/build/shell-scripting/ch01s04.html | |
##### fd (FILE DESCRIPTORS) ##### | |
# 0 == stdin | |
# 1 == stdout | |
# 2 == stderr | |
# & == pointer (`2>&1`) | |
# &> == `2> <file> 1> <file>` (file direction) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# https://github.com/estysdesu/dotFiles/blob/master/bash/.bash_profile | |
# one-liner | |
alias spotify_web="'`locate "*Google\ Chrome"`' --app="https://play.spotify.com"" # Spotify web client without all the junk | |
# functional | |
chrome_app=`locate "*Google\ Chrome"` | |
web_app () { | |
"$chrome_app" --app="$1" |