guest@dotshare [~/groups/shells/bash] $ ls deterenkelts-bashrc/ | cat

deterenkelt’s .bashrc (scrot)

deterenkelt Jul 17, 2015 (shells/bash)

.bashrc(raw, dl)

SCROT

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# /etc/skel/.bashrc
#
# This file is sourced by all *interactive* bash shells on startup,
# including some apparently interactive shells such as scp and rcp
# that can't tolerate any output.  So make sure this doesn't display
# anything or bad things will happen !

# This is to dispose of old aliases and function definitions before
#   (re-)sourcing new or rewritten ones.

unalias -a
# If I replace it with
#     unset -f `declare -F | sed 's/^declare -f //g'`
# won’t it break something that have been read from /etc/…?
unset -f `sed -nr "s/^\s*([-_a-zA-Z0-9]+)\(\)\s*\{.*$/\1/p" \
          ~/.bashrc ~/bashrc/* 2>/dev/null`

[ -v ENV_DEBUG ] || {
	rm -rf /tmp/envlogs/* &>/dev/null
	mkdir -m 700 /tmp/envlogs &>/dev/null # /tmp should be on tmpfs
}
# code     file               logfile (under /tmp/envlogs/)
# x    /usr/bin/X          x (just for the mention, it’s always present)
# p    ~/.preload.sh       preload
# i    /usr/bin/i3         i3.stdout + i3.stderr
# g    ~/.i3/g…_for_i3bar  gentext4i3bar
# a    ~/.i3/autostart.sh  autostart
# r    ~/bin/run_app.sh    runapp_<app_name>
# q    ~/.i3/on_quit.sh    on_quit
# -    prevents the variable to be empty
export ENV_DEBUG=-pq
for opt in autocd cdspell dirspell dotglob extglob globstar \
    no_empty_cmd_completion; do
    shopt -s $opt
done
for completion_module in eix eselect gentoo git gpg iptables layman man \
    smartctl ssh strace sysctl taskset tmux udisks watchsh; do
    eselect bashcomp enable $completion_module &>/dev/null
done
unset opt completion_module
# man bash says that non-login shells do not source /etc/profile and
#   ~/.bash_profile. My shells are non-login, however, they have PATH set
#   and they source ~/.bash_profile (which is sourcing this file
#   in its turn). A miracle.
. /etc/profile.d/bash-completion.sh

# Testing ur PAM
#ulimit -S -n 8192
# Setting the ‘soft’ limit of maximum open files.
ulimit -Sn 4096
set -b # report exit status of background jobs immediately

export DEPLOY_EXCLUDE_DIRS="$HOME/.ssh|$HOME/.gnupg"
export EIX_LIMIT=0
export EDITOR="emacsclient -c -nw"
export LESS='-R -M --shift 5 -x4'
export MPD_HOST=$HOME/.mpd/socket
#grep -qF '/assembling/' <<<"$PATH" \
#	|| export PATH="$PATH:~/assembling/android-sdk-linux/platform-tools/:~/assembling/android-sdk-linux/tools/"
grep -qF '/usr/games/bin/' <<<"$PATH" \
	|| export PATH="$PATH:/usr/games/bin/"
export PS1="\[\e[01;34m\]┎ \w\n\[\e[01;34m\]┖ \
\`echo \"scale=2; \$(cut -d' ' -f2 </proc/loadavg) /\
    \$(grep ^processor </proc/cpuinfo | wc -l)\" | bc\` \
\[\e[01;32m\]\
\`[ \u = \"$ME\" ] \
    ||{ [ \u = root ] && echo -n \"\[\e[01;31m\]\"; } \
|| echo -n \"\[\e[01;37m\]\u \"\`\
\[\e[01;32m\]\
at \h \
\[\e[01;34m\]\\$\[\e[00m\] "

## Aliases caveats and hints:
## 1. All innder double quotes must be escaped
#     alias preservequotespls="echo \"naive example!\""
## 2. Every call of subshell must be escaped or it will be executing
#     at the time this file loads.
#     alias dontlistmyhomefolderpls="for i in \`ls\`; do ls $i; done"
## 3. To prevent early expanding of variable names, one can use single
#     quotes or escaping, or both if situation requires so.
#     alias hisbashrcpls="sudo -u another_user /bin/bash -c 'nano \$HOME/.bashrc'"
## 4. Aliases can have multiple lines
#     alias plsplsplsdontbreak="echo some stuff # this is comment
#                               echo lol second line # another comment"

# add to todo list
a() { echo "$@" >> ~/todo; }
# delete from todo list
d() {
    [ "$1" = '-' ] && echo -n >~/todo || {
        for i in $@; do
            [[ "$i" =~ ^[0-9]+$ ]] && sed -i $1d ~/todo
        done
    }
}
alias bc="bc -q"
alias ec="emacsclient -c -nw"
alias emc="emacsclient"
alias erc="emacsclient -c -nw ~/.bashrc"
alias grep="grep --color=auto"
# pinentry doesn’t like scim
alias gpg="GTK_IM_MODULE= QT_IM_MODULE= gpg"
alias ls="ls --color=auto"
alias re=". ~/.bashrc" # re-source
spr="| curl -F 'sprunge=<-' http://sprunge.us" # add ?<lang> for line numbers
#alias td="todo -A "
#alias tdD="todo -D "
alias tmux="tmux -u -f ~/.tmux/config -S $HOME/.tmux/socket"
alias deploy="/root/scripts/deploy_configuration.sh "

#[ -v SSH_CLIENT ] && . ~/.preload.sh

# Test for an interactive shell.  There is no need to set anything
# past this point for scp and rcp, and it's important to refrain from
# outputting anything in those cases.
[[ $- = *i* ]] || return 0

[ ! -v DISPLAY -a "`tty`" = /dev/tty2 ] && {
	# W! startx IGNORES ~/.xserverrc options if something passed beyond -- !
	# This will use /etc/X11/xorg.conf as a default config
	exec startx -- -nolisten tcp &>/tmp/envlogs/x # … -- -verbose 5 -logverbose=5
	# This was needed when I used to switch between configs.
	# exec startx -- -config xorg.conf$(<~/.xorg.conf.suffix) -nolisten tcp &>/tmp/envlogs/x
	# rm ~/.xorg.conf.suffix &>/dev/null
}

pushd ~/bashrc >/dev/null
hostnamerc=${HOSTNAME%.*}.sh
[ -r $hostnamerc ] && . $hostnamerc
popd >/dev/null

# This is for one-command urxvt
one_command_execute() {
	exec &>/dev/null
	# TAB completion puts an extra space after the command.
	READLINE_LINE=${READLINE_LINE%%+([[:space:]])}
	until [ -v all_aliases_expanded ]; do # recursive alias expansion
		# Tabulation cahracter may be used in user’s aliases.
		local first_word=${READLINE_LINE%%[[:space:]]*}
		[ "$first_word" = "$old_first_word" ] && break # to prevent a loop
		alias -p | grep -q "^alias $first_word='.*'$" && {
			local cmd=`alias -p | sed -nr "s/^alias $first_word='(.*)'$/\1/p"`
			# escape all special characters in the expanded alias is more
			#   consuming, than just stripping its name and combining
			#   a new string.
			READLINE_LINE=${READLINE_LINE/#$first_word/}
			READLINE_LINE="$cmd $READLINE_LINE"
			local old_first_word="$first_word"
		} || local all_aliases_expanded=t
	done
	(nohup $READLINE_LINE) &
	local c=0
	until [ $((c++)) -eq 3 ]; do
		xdotool search --onlyvisible --pid $! &>/dev/null && break
		sleep 1
	done
	exit
}

[ -v ONE_COMMAND_SHELL ] && {
	PS1='\[\e[01;37m\](☞°ヮ°)☞\[\e[00m\] '
	## This doesn’t work now, so I have to use default binding C-M-e to
	##   expand aliases before they’ll go to nohup.
	# shopt -s expand_aliases # actually, this may be needed only inside
	#                         # of the subshell
	# bind shell-expand-line
	bind -x '"\C-m":"one_command_execute"'
}

CLICK TO VIEW

x

iforgot.sh(raw, dl)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
# iforgot.sh
# This bash source file is for functions showing you
# samples of code that you always forget.

# <<EOF expands heredoc, <<"EOF" leaves it as is.

iforgot() {
	local keywords="$@"
	[ "$keywords" ] || {
		read -p 'What have you forgot, darling? > '
		local keywords="$REPLY"
		echo "Thanks, also you can use parameters to this function, like"
		echo -e "\tiforgot <what>"
	}
	for keyword in $keywords; do
		declare -F | sed -nr 's/^declare -f (iforgot-.*'$keyword'.*)/\1/p'
	done
}

iforgot-restart-daemons-from-the-runlevel-i-am-in() {
echo 'USE CAREFUL.'
cat <<"EOF"
	for i in `rc-update | sed -rn 's/[ ]+([^ ]+) \| '"runlevel"'.*/\1/p'`; do
		/etc/init.d/$i restart
	done
EOF
}

iforgot-make-etags-for-emacs() {
cat <<"EOF"
	find . -name '*.c' -exec etags -a {} \;
EOF
}

iforgot-htmlize-my-code() {
	echo man code2html
}

iforgot-mount-options-for-my-flash-stick() {
	echo mount -t vfat -o user,rw,fmask=0111,dmask=0000,codepage=866,nls=iso8859-5,utf8,noexec
}

iforgot-uname-opts() {
	for i in a s n r v m p i o; do
        echo -e "\t-$i\t`uname -$i`"
    done
}

iforgot-check-gcc-options() {
	set -x
	gcc -Q -march=atom --help=target | grep fpmath
	gcc -Q --help=optimizers | grep enable
	set +x
}

iforgot-xkb-opts-retrieval-from-gnome2() {
	set -x
	gconftool-2 -R /desktop/gnome/peripherals/keyboard/kbd
	set +x
}

iforgot-xkb-opts() {
	set -x
	less /usr/share/X11/xkb/rules/evdev.lst
	set +x
}

iforgot-android-screenshot-via-sdk() {
	echo "ddms"
}

iforgot-load-all-possible-sensors-modules() {
cat <<"EOF"
	for i in `modprobe -l | sed -rn 's|.*/hwmon/([^/]+)$|\1|p'`; do
		modprobe $i
	done
EOF
}

iforgot-fsck-force-check() {
	echo -e \\t touch /forcefsck
}

iforgot-make-a-debug-build() {
cat <<"EOF"
	FEATURES="ccache nostrip" \
		USE="debug" \
		CFLAGS="…-ggdb" \
		CXXFLAGS="<CFLAGS>" \
		emerge $package
OR
	gdb --pid <pid>
	thread apply all bt
EOF
}

iforgot-read-via-x0() {
cat <<"EOF"
	while IFS= read -r -d $'\0'; do
		echo "$REPLY"
	done <  <(find -type f -print0)

	(-d '' also works since \0 is a marker for an empty string.)
EOF
}

iforgot-where-is-my-completion() {
cat <<"EOF"
    eselect bashcomp list --global
    eselect bashcomp enable --global base
    eselect bashcomp enable --global man
    eselect bashcomp enable --global gentoo
    env-update && . /etc/profile
EOF
}

iforgot-what-is-that-window-class() {
	echo -e \\txprop
}

iforgot-what-to-do-if-something-messed-the-fonts() {
cat <<"EOF"
	xset +fp /usr/share/fonts/terminus && xset fp rehash
EOF
}

iforgot-extended-regex-purpose() {
	set -x
	shopt -s extglob && abc='000123' && echo ${abc##+(0)}
	set +x
}

iforgot-how-to-trace-and-debug() {
cat <<EOF
	# Trace library and system calls:
	strace -p PID
	ltrace -p PID
	# Look for opened files of process with pid PID
	ls -l /proc/PID/fd/*
	# Kill a process to see its core
	kill -11 PID
EOF
}

iforgot-bookmarks-in-manpages() {
cat <<"EOF"
	man -P 'less -p \"^\s+Colors\"' eix
EOF
}

iforgot-git-new-repo() {
cat <<"EOF"
	git init
	git remote add origin git@example.com:project_team.git
                          ssh://git@example.com:port/reponame.git
    git add .
	git commit -m "fgsfds"
	git push origin refs/heads/master:refs/heads/master
EOF
}

iforgot-select-figlet-font-for-me() {
cat <<"EOF"
	echo '' > ~/cool_fonts
	for i in `ls /usr/share/figlet/*flf`; do
		clear
		echo $i
		figlet -f $i -c 12345
		figlet -f $i -c 67890
		read -n1
		[ $REPLY = 'y' ] && echo $i>>~/cool_fonts
	done
	cat ~/cool_fonts
EOF
}

iforgot-draw-me-cool-figlet-fonts() {
cat <<"EOF"
	for i in `cat ~/cool_fonts`; do
		echo $i
		figlet -f $i -c 12345
		figlet -f $i -c 67890
	done
EOF
}

iforgot-chroot-procedure() {
cat <<"EOF"
	mount -t proc none /mnt/chroot/proc
	mount --rbind /sys /mnt/chroot/sys
	mount --rbind /dev /mnt/chroot/dev
	[linux32] chroot /mnt/chroot /bin/bash

		env-update && source /etc/profile
		export PS1="(chroot) $PS1"
		# mount /boot /usr etc.exit

	umount -l /mnt/chroot/proc
	umount -l /mnt/chroot/dev{/pts,/shm}
	umount -l /mnt/chroot/sys
EOF
}

iforgot-ordinary-user-groups() {
	echo -e "\tuseradd -m -G audio,cdrom,games,plugdev,cdrw,floppy,portage,usb,video,wheel -s /bin/bash username"
}

# SMART
iforgot-smart-immediate-check() {
	echo -e '\tsmartctl -H /dev/sdX'
}

iforgot-smart-selftest-short-now() {
	echo -e '\tsmartctl -t short /dev/sdX'
}

iforgot-smart-selftest-long-now() {
	echo -e '\tsmartctl -t long /dev/sdX'
}

iforgot-smart-selftest-long-later() {
	echo -e '\tsmartctl -t long -s L/../.././23'
}

iforgot-smart-selftest-sheduling-syntax() {
	echo -e "\t man -P\"less -p'^\s+-s REGEXP'\" smartd.conf"
}

iforgot-mark-bad-sector-with-badblocks() {
cat <<"EOF"
    If situation looks like this

# smartctl -a /dev/sda
SMART Attributes Data Structure revision number: 10
Vendor Specific SMART Attributes with Thresholds:
ID# ATTRIBUTE_NAME          FLAG     VALUE WORST THRESH TYPE      UPDATED  WHEN_FAILED RAW_VALUE
…
  5 Reallocated_Sector_Ct   0x0033   099   099   036    Pre-fail  Always       -       61
…
197 Current_Pending_Sector  0x0012   100   100   000    Old_age   Always       -       1
198 Offline_Uncorrectable   0x0010   100   100   000    Old_age   Offline      -       1

…

SMART Self-test log structure revision number 1
Num  Test_Description    Status                  Remaining  LifeTime(hours)  LBA_of_first_error
# 1  Extended offline    Completed: read failure       20%     22638         1670581106

    Then seeking for a badblock will look like that

badblocks -vs -b512 /dev/sda 1670581106 1670581106

    -v – verbose, -s shows progress, -b is block size, 512 since 1670581106 is
  an LBA, i.e. sector address and sectors are usually are 512 bytes long.
  First address is the end of the range where badblocks seek, and the last one
  points at the start of the range. Also there are useful -n and -w options
  which mutually exclude themselves – -n safely rewrites block’s contents,
  -w rewrites it with binary patterns and causes data loss. By default
  badblocks does only read-only check (that works for me).

    If it confirms the sector is truly bad, then we need to get the address
  in blocks on your partition, the offset, an pass it as the number of block
  as your filesystem understands, usually it is multiple of 512, e.g. 4096.

fdisk /dev/sda

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *          63       80324       40131   83  Linux
/dev/sda2           80325   104952644    52436160   83  Linux
/dev/sda3       104952645   109161674     2104515   83  Linux
/dev/sda4       109162496  1953525167   922181336   83  Linux

    So, the problem LBA belongs to /dev/sda4, now get the offset on that
partition.

echo 'scale=3;(1690581106-109162496)/8' | bc
195177326.25

    Fraction part means it is the second sector of eight in that block.
   (Since one block of 4096 bytes contains 8*512 bytes sectors, 1/8 is
     0.125 and 2/8 is 0.25)
    The formula is

<bad_LBA> - <start_LBA_of_its_partition> / (<fs_block_size> / <sector_size>)

    So, produce the list

echo '(1690581106-109162496)/8' | bc > /tmp/bb_list

    And call e2fsck

umount /<mountpoint for partiton with bad LBA>
e2fsck -l /tmp/bb_list /dev/sdX

    If e2fsck called with -L option instead of -l, the passed file will rewrite
  all the list of badblocks contained in the filesystem. That list can be
  checked with

dumpe2fs -b /dev/sda4

EOF
}

# Wi-Fi
iforgot-wifi-connect() {
cat <<"EOF"
    iwconfig wlan0 \
                   essid <point name> \
                   mode managed       \
                   key s: <password>

    ifconfig wlan0 <ip address> netmask <mask>
EOF
}

iforgot-wifi-scan() {
	echo -e "\tiwlist wlan0 scanning"
}

iforgot-ffmpeg-2-pass-vbr-encoding() {
cat <<"EOF"
    ffmpeg -y -i "$input_file" -an -pass 1 -threads 3 \
           -vcodec libx264 -vpre slow_firstpass "$tmpfile"

    ffmpeg -y -i "$input-file" \
           -acodec libfaac -ar 44100 -ab 192k \
           -pass 2 -threads 3 \
           -vcodec libx264 -b 2000k -vpre slow "$tmpfile" "$output-file"
EOF
}

iforgot-tee-usage() {
cat <<"EOF"
    wget -O - http://example.com/dvd.iso \
        | tee dvd.iso | sha1sum > dvd.sha1

    wget -O - http://example.com/dvd.iso \
        | tee >(sha1sum > dvd.sha1) \
              >(md5sum > dvd.md5) \
              > dvd.iso

    tardir=your-pkg-M.N
    tar chof - "$tardir" \
        | tee >(gzip -9 -c > your-pkg-M.N.tar.gz) \
        | bzip2 -9 -c > your-pkg-M.N.tar.bz2
EOF
}

iforgot-emoji-drawing() {
cat <<"EOF"
▽△ ▲▼    sankaku
☆★*      hoshi
〆        shime
米※       kome
益        yaku

⚈д⚈ ⌕…⌕ °ヮ° ´Д`(^▽^)╯ /(⌃ o ⌃)\ (^◊^)╮ ◜(◙д◙)◝

キタ━━━(゜∀゜)━━━!!!!!   ‘It’s here’, Kitaa!, a general expression
                        of excitement that something has appeared
                        or happened or ‘I came’.
(・∀・)~mO               Flash of intuition
m9(・∀・)                NO U
ヽ(°Д°)(╬♉益♉)ノ
Ԍ──┤ユ(#◣д◢)
(☞゚ヮ゚)( `)>	                Salute
(*゚ノO゚)<オオオオォォォォォォォーーーーーイ!	Calling out, "Ooooi!"
Σ(゜д゜;)	            Shocked
(*´Д`)ハァハァ               Erotic stirring, haa haa
(゚Д゚;≡;゚Д゚)
(・∀・)つ⑩
щ(゚Д゚щ)(屮゚Д゚)屮          Come on
(・A・)                ‘That’s bad’
(*⌒▽⌒*)
\|  ̄ヘ ̄|/_______θ☆( *o*)/	Kick
(l'o'l)	                Shocked
(╯°ロ°)╯  ┻━━┻
┬──┬ ノ( ゜-゜ノ)
EOF
}

iforgot-sed-newline-simple-removal() {
cat<<"EOF"
    echo -e '1\n2\n3\n4\n5' | sed -rn '1h; 2,$ H; ${x;s/\n/---/g;p}'
EOF
}

iforgot-set-default-wine-environment-wineprefix() {
	set-wineprefix
}

iforgot-diff-patch() {
	echo -e "\tdiff -u file1 file2"
}

iforgot-gpg-privkey() {
cat <<"EOF"
Very good! Now, like I said above, using this is pretty much like using a “regular” GPG keypair; the only exception is when signing other people’s keys, or add or revoking subordinate keys. For this you build a command pointing to the two locations. For example,

    gpg --homedir /media/Secure/dotgnupg/ \
        --keyring ~/.gnupg/pubring.gpg \
        --secret-keyring ~/.gnupg/secring.gpg \
        --trustdb-name ~/.gnupg/trustdb.gpg \
        --edit-key MYKEYID

should allow you to add or revoke subordinate keypairs, or do any other operation that requires the private master key. You should keep in mind though, that changes to keys other than your own will be done on your “everyday” GPG folder (~/.gnupg), but changes to your own key—adding a new subkey, for example—will be done on the secure location (/media/Secure/dotgnupg). After doing such a change, you must export your key (in the example to the file aux.asc), and re-import it to the everyday GPG folder:

    gpg --homedir /media/Secure/dotgnupg/ \
        --output aux.asc \
        --armor \
        --export MYKEYID
    gpg --import aux.asc
    rm aux.asc
EOF
}

iforgot-io-monitoring() {
	echo iotop
}

iforgot-last-argument-passed-to-shell() {
	echo 'echo !$'
}

iforgot-qemu-create-image() {
cat <<EOF
	qemu-img create -f qcow2 -o
		compat=1.1,
		cluster_size=512,
		preallocation=metadata,
		lazy_refcounts=on
	<filename> <size>
EOF
}

iforgot-du-sort() {
	echo -e '\tdu -hsx * | sort -h'
}

iforgot-fonts-list() {
	echo -e '\tfc-list'
}

iforgot-fsck-with-progressbar() {
cat<<EOF
	fsck -C -l /dev/sdb3 -- -c -f -y
	       \  \    \          \  \  \_ autoyes
	        \  \    \          \  \_ check even if fs looks clean
	         \  \    \          \_ check for bad blocks
	          \  \    \_ partition with filesystem
	           \  \_ lock the whole-disk device by an exclusive flock(2)
	            \_ use progressbar/completion for checkers that support it
	              (generally ext2/3/4)
EOF
}

iforgot-completion-keys() {
cat<<"EOF"
	"\e@": complete-hostname
	"\e{": complete-into-braces
	"\e~": complete-username
	"\e$": complete-variable
EOF
}

iforgot-shell-colours(){
cat<<EOF
	There are only 8 colors in general. From man terminfo:
	Color     #define         Value   RGB
	black     COLOR_BLACK       0     0, 0, 0
	red       COLOR_RED         1     max,0,0
	green     COLOR_GREEN       2     0,max,0
	yellow    COLOR_YELLOW      3     max,max,0
	blue      COLOR_BLUE        4     0,0,max
	magenta   COLOR_MAGENTA     5     max,0,max
	cyan      COLOR_CYAN        6     0,max,max
	white     COLOR_WHITE       7     max,max,max

	Escape sequence to set a color is \e[00;3xm, where x is 0–7.
	Some interesting capabilities:
EOF
echo -e '	- \e[0;1mbold:\e[00m \\e[0;1m (in normal terminals bold replaced\n	  with bright version of a color);'
echo -e '	- \e[0;4munderline:\e[00m \\e[0;4m (don’t expect that the line will be\n	  of same color as the char above it);'
echo -e '	- \e[07;36mreverse:\e[00m \\e[0;7m (background and foreground);'
echo -e '	- stop: \\e[00m.\n'
echo -e '	Example of \\e[01;32m\e[01;32mbold green text\e[00m\\e[00m.'

cat <<EOF

	As far as I know, there’s no way to query the colors of the terminal
emulator. You can change them with \e]4;NUMBER;#RRGGBB\a (where NUMBER is
the terminal color number (0–7 for light colors, 8–15 for bright colors)
and #RRGGBB is a hexadecimal RGB color value) if your terminal supports
that sequence (reference: ctlseqs). —http://unix.stackexchange.com/a/1772/10075
See also http://misc.flogisoft.com/bash/tip_colors_and_formatting
EOF
}

iforgot-webm-conversion() {
cat <<"EOF"
	ffmpeg -threads 4 -i input.mov \
	       -acodec libvorbis -ac 2 -b:a 192k -ar 44100 \
	       -b:v 1000k -s 640x360 output.webm
EOF
}

iforgot-x264-conversion() {
cat <<EOF
	ffmpeg -threads 4 -i input.mov \
	       -acodec libfaac -b:a 96k \
	       -vcodec libx264 -vpre slower -vpre main \
	       -level 21 -refs 2 -b:v 345k -bt 345k \
	       -threads 0 -s 640x360 output.mp4
EOF
}

iforgot-image-conversion() {
cat <<EOF
	ffmpeg  -y -threads 4 -pattern_type glob \
	        -framerate 1/5 -i "file_name_000*.png" \
	        -c:v libvpx -r 1 -pix_fmt yuv420p out.webm

https://trac.ffmpeg.org/wiki/Create%20a%20video%20slideshow%20from%20images
EOF
}

iforgot-clean-gentoo() {
cat <<EOF
	# Remove unnecessary packages
	1. emerge -av --depclean
	# …distfiles except matching by exact installed version
	    and those downloaded earlier than two days ago.
	    2w [eeks] 3m [onth] also accepted.
	2. eclean-dist -d -t2d
	# Remove binary packages
	3. eclean packages
EOF
}

iforgot-cut-video-with-ffmpeg() {
cat <<EOF
	ffmpeg -y -threads 8 -i in.webm -ss 00:00:01 -t 00:02:22 -async 1 -b:v 500k out.webm

+crop
	-filter:v "crop=WIDTH:HEIGHT:X_OFFSET:Y_OFFSET"

Webm issues: it ifnores -b:v -minrate -maxrate and -crf. Use -qmin and -qmax.
	ffmpeg -y -threads 8 -async 1 \
		-i /home/video/anime/\[ReinForce\]\ Ergo\ Proxy\ \(BDRip\ 1920x1080\ x264\ FLAC\)/\[ReinForce\]\ Ergo\ Proxy\ -\ 11\ \(BDRip\ 1920x1080\ x264\ FLAC\).mkv  -ss 00:00:00 \
		-t 00:00:15.849 -b:v 12M -crf 4 -minrate 12M -maxrate 12M -qmin 0 -qmax 0 -vf scale=1280:720 /tmp/out.webm
EOF
}

iforgot-catenate-video-with-ffmpeg() {
cat <<EOF
	find . -iname "part*.webm" | sort >files
	ffmpeg -y -threads 8 -f concat -i files -c copy -async 1 out.webm
EOF
}

iforgot-create-video-from-image-sequence-with-ffmpeg() {
echo 'ffmpeg -y -framerate 1/5 -pattern_type glob_sequence -i "./[Commie] Psycho-Pass 2 - 08 [A844F60A]_%*.png" -c:v libvpx -b:v 500k -r 30 -pix_fmt yuv420p out.webm && mpv out.webm'

echo Actually, someday they should fix -pattern_type glob and '*.png' and '%d'
}

iforgot-record-my-desktop() {
	set -x
	man -P"less -p'^\s*X11 grabbing'" ffmpeg
	set +x
}

iforgot-check-own-process-memory() {
cat <<EOF
	pmap from procps.
	# pmap -d `pidof X`
	Writeable — this is it.
EOF
}

iforgot-commie-check-whats-up() {
	echo -e "\t.blame <what>"
}

iforgot-firefox-settings() {
cat <<EOF
See ~/.mozilla/profile.default/user.js
To check:
    about:cache
    about:cache?device=memory

In case of troubles with SWF
   echo 'application/x-shockwave-flash       swf swfl' > .mime.types
EOF
}


iforgot-mpv-crunchyroll-streaming() {
	# requires ffmpeg to be compiled with networking and rtmp
	echo 'mpv --ytdl http://www.crunchyroll.com/parasyte-the-maxim-/episode-1-metamorphosis-662583'
}


iforgot-audio-recording() {
cat <<EOF
Record:
	arecord -f cd -t wav `date +s`.wav

Conversion to MP3 VBR
     ffmpeg -i 19122014.wav -codec:a libmp3lame -qscale:a 9 output.mp3
                                                          ^
                                                      lame quality

 lame    Avg    b/rate range  ffmpeg
option  kbit/s     kbit/s     option

-b 320   320      320 CBR     -b:a 320k (non VBR. NB this is 32KB/s, or its max)
-V 0     245      220-260     -q:a 0 (NB this is VBR from 22 to 26 KB/s)
-V 1     225      190-250     -q:a 1
-V 2     190      170-210     -q:a 2
-V 3     175      150-195     -q:a 3
-V 4     165      140-185     -q:a 4
-V 5     130      120-150     -q:a 5
-V 6     115      100-130     -q:a 6
-V 7     100       80-120     -q:a 7
-V 8      85       70-105     -q:a 8
-V 9      65        45-85     -q:a 9
EOF
}

iforgot-wcpe-station-time-zone-difference() {
	-8
}

iforgot-libreoffice-writer-images() {
	When an image is inserted in a libreoffice writer document, lowriter uses 90 dpi by default. Thus, importing SVG file in GIMP it’s necesary to set corresponding dpi and count appropriate width according to that. GIMP advises 1000px width by default, but that gives 282.24 mm of width after import to libreoffice. ESPD doc width excluding fields is 180 mm. After import to lowriter, in the document body image will look awry even if you guess the 100 % scale right. But it only seems like it, after the export to PDF with lossless image compression it’ll look as it should.
}

iforgot-libreoffice-pdf-export() {
	take off flag  embedding ODT when sending to potential employer.
	set flag for PDF/A-1a, that format is for docs to be stored for a long term. Fonts are embedded.
}

iforgot-pdf-split() {
	echo -e '\t$ gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER -dFirstPage=1
-dLastPage=4 -sOutputFile=outputT4.pdf T4.pdf'
}

iforgot-pdf-grep() {
	cat <<"EOF"
	find /path -name '*.pdf' -exec sh -c 'pdftotext "{}" - | grep --with-filename --label="{}" --color "your pattern"' \;
EOF
}

iforgot-ffmpeg-add-image-to-video() {
	cat<<"EOF"
	# Add five seconds of video
	ffmpeg -loop 1 -f image2 -i image.png -r 30 -t 5 image.webm
	# Create input file for ffmpeg
	find -iname "*.webm" -printf "file '%p'\n" | sort >inp
	# Catenating the files
	ffmpeg -f concat -i inp -codec copy output.webm
EOF
}

iforgot-voip-via-netcat() {
	cat <<"EOF"
	(read; echo; rec --buffer 17 -q -w -s -r 48000 -c 1 -t raw -)|netcat -u -l -p 8888|(read; play -w -s -r 48000 --buffer 17 -t raw -)
	(echo; rec --buffer 17 -q -w -s -r 48000 -c 1 -t raw -)|netcat -u 192.168.1.1 8888|(read; play -w -s -r 48000 --buffer 17 -t raw -)
EOF
}

#removes *.desktop files
iforgot-wine-clean-desktop() {
	rm /home/sszb/.wine/drive_c/users/sszb/#msgctxt#directory#Desktop/*
}

iforgot-wget-mirror-site() {
	cat <<"EOF"
	wget --mirror --convert-links --adjust-extension --page-requisites --no-parent http://example.org'
or shorter:
	wget -mkEpnp http://example.org
EOF
}

iforgot-wifi-why-it-doesnt-work() {
cat <<"EOF"
	card is requiring CONFIG_CFG802011_WEXT=y
	card is hw/soft bloced: rfkill list
	card is in wrong CRDA region: iw reg get/set <AA>
EOF
}
 

x

Notes

In the centre is an urxvt window with WM_CLASS one_command_shell. It behaves like a launcher and exits after launching just one command. It’s better than other launchers, because it is using a true shell that inherits all aliases in ~/.bashrc and stuff. It’s launched from my i3 config, https://github.com/deterenkelt/dotfiles/blob/master/.i3/config.template

In the right terminal there’s a script called ‘iforgot’ where I store snippets of shell code. It can be found here and updated version is always on github, https://github.com/deterenkelt/dotfiles/blob/master/bashrc/iforgot.sh