The stuff I do

Bash arrays [bash][array]

Initiate an array

myArray=( element_1 element_2 element_n )

Access item by index

echo ${myArray[2]}

Iterate through array

To iterate over the elements:

for element in "${array[@]}"
echo "$element"

To get both the index and the value:

for index in "${!array[@]}"
echo "$index ${array[index]}"
Creating zsh completion function [shell][zsh]

A quick trick to have custom completion on the aliases I create.

First create the function and the alias, they can be in ~/.bash_aliases or whatever.

myCoolFunction() {
echo "Here are the args from my function $@"
alias mcf='myCoolFunction'

Then create the completion function (best practice underscore+function name) which can be anywhere too. An interesting list of the helpers provided by zsh for the completion functions is here.

_myCoolFunction() {
compadd "$@" foo bar baz

Finally in ~/.zshrc we can register _myCoolFunction as the completion function of myCoolFunction:

compdef _myCoolFunction myCoolFunction

Once everything is ready in a new shell typing mcf <TAB> should yield the 3 completions options.

If things don't work one can check the completion function for a particular function (It does not work with the alias) with:

echo $_comps[myCoolFunction]

and the implementation with

functions $_comps[myCoolFunction]

Finally I should check how to make it work with the defined files (~/.oh-my-zsh/completions) and understand why the compdef command only works when put in .zshrc.

Fixing commits in git [git][commit]

This link is dope

TODO: Extract the ones I need but can never remember

Remove commit from history

Reminder on zsh escape ^ in HEAD^ with HEAD\^

Remove the last commit of the history completely and discard changes

git reset --hard HEAD^

Remove the last commit from history but keep the working tree

git reset HEAD^

Sign an older commit in your branch

This will do an interactive rebase, playing git commit --amend --no-edit -n -S
after each commit

(Check if -n is useful I can't find it in the man)

git rebase --exec 'git commit --amend --no-edit -n -S' -i my-branch
Screen [screen]

Basic usage

Description Command
Start a new session with session name screen -S <session_name>
List running sessions / screens screen -ls
Attach to a running session screen -x
Attach to a running session with name screen -r <session_name>
Detach a running session screen -d <session_name>
Shell redirections [bash][shell][output]

Redirect stdout and stderr to a file

command > /dev/null 2>&1