books on zlib official

vim cheatsheet

# Opens files in tabs
vim -p file1 file2

# Open all searched files
# :args to show file list
# :n to open next file
# :N to open prev file
vim `find . -name "strings.xml"`

# Re-sync syntax highlighting
:syntax sync fromstart

Custom key for SSH

$ ssh-keygen
Enter file in which to save the key (/home/petr/.ssh/id_rsa): /home/petr/my.key
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/petr/my.key.
Your public key has been saved in /home/petr/my.key.pub.
The key fingerprint is:
SHA256:t7oRcfThgNf5w8kXl+pg6Xgso/BJtBDt4T42vFUpZ7U petr@pc
The key's randomart image is:
+---[RSA 2048]----+
|      .  .o...  .|
|     . o...+oo o.|
|      + o.. *+o.o|
|     . + + O E* .|
|      = S @ o  o |
|     . O B = .   |
|      = O =      |
|       = o       |
|        o.       |
+----[SHA256]-----+

To use this key you have 2 choices: run command

ssh -i ~/my.key posvic.eu

or edit SSH config file and specify IndetityFile for host. Then is no need to use parameter -i.

# ~/.ssh/config
Host posvic.eu
    IdentityFile ~/my.key
ssh posvic.eu

Bash cheatsheet

files=(Screen*.png)
if [ $files = "Screen*.png" ]; then
  echo "No match"
else
  # Override or append
  files[2]="test1"

  # Remove
  files=("${files[@]:0:1}" "${files[@]:3:4}")

  # Length
  echo ${#files[@]}

  for file in "${files[@]}"; do
    echo "$i"
  done

  for ((i = 0; i < ${#files[@]}; i++)); do
    echo "${files[i]}"
  done
fi
case "$a" in
"a")
  echo "a"
  ;;
"b")
  echo "b"
  ;;
*)
  echo "else"
  ;;
esac
path="/var/www/html"
echo ${path##*/} # Last directory
# # from beginning, shortest match
# ## from beginning, longest match
# % from end, shortest match
# %% from end, longest match

Change prompt in Ranger

In previous post I wrote about file manager Ranger. In Ranger there is keyboard shortcut Shift + S to execute shell (Bash in my case). You can modify /etc/ranger/config/rc.conf (or your local ~/.config/ranger/rc.conf) and add this line:

map S shell bash --rcfile <(cat ~/.bashrc; echo 'PS1="(ranger) $PS1"')

Then you get your prompt prefixed by (ranger) and always know you are in shell of Ranger.