tldr-missing-pages 967 Bytes
Newer Older
1
2
#!/usr/bin/env bash

3
4
# Written by Starbeamrainbowlabs <https://starbeamrainbowlabs.com>
# Source: https://gitlab.com/sbrl/bin/blob/master/tldr-missing-pages
5
# Available to install in my personal apt repo: https://apt.starbeamrainbowlabs.com/
6

7
8
9
10
11
12
process_command() {
	if which "$1" >/dev/null 2>&1 && ! tldr "$1" >/dev/null 2>&1; then
		echo "$1";
	fi
}

13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# $1 - mode
get_commands() {
	case $1 in
		man )
			apropos -s 1 . | awk '{ print $1 }';
			;;
		history )
			awk '{print $2}' <"$HOME/.bash_history" | sort | uniq | grep -iP '^[a-zA-Z0-9]+$';
			;;
	esac
}

if [ "${1}" = "" ]; then
	echo "Error: No mode specified.";
	echo "Use it like this:";
	echo "    tldr-missing-pages {{mode}}";
	echo "Modes:";
	echo "    history - Search your ~/.bash_history file";
	echo "    man - Search the man pages";
	exit 1;
fi


36
37
38
39
# N=$(expr "$(nproc) * 3");
while read nextcmd; do
	# ((i=i%N)); ((i++==0)) && wait
	process_command "${nextcmd}" &
40
done < <(get_commands "${1}") | sort;