aboutsummaryrefslogtreecommitdiff
path: root/functions/lscmd.fish
blob: 0c9c34afa01ba3a33b059fce69d65dab1ef0053b (plain)
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
function lscmd --description "Show installed useful command line tools"

set progsfile "$__fish_config_dir/progs.csv"

if not check_install 'textql'
  echo "Can't find textql."
  return 1
end

if not functions -q is-installed
  echo "No is-installed function defined."
  return 1
end

function _get_basedbname -a progdb
  set -f baseprogdbname (path basename $progdb)
  echo (path change-extension '' $baseprogdbname)
end

function _get_categories -a progdb
  set bnprogdb (_get_basedbname $progdb)
  command textql -header -sql "SELECT DISTINCT category FROM $bnprogdb" $progdb
end

function _get_progs_by_category -a progdb -a category
  set bnprogdb (_get_basedbname $progdb)
  command textql -header -sql "SELECT name FROM $bnprogdb WHERE category = '$category'" $progdb
end

function _get_desc_by_progname -a progdb -a progname
  set bnprogdb (_get_basedbname $progdb)
  command textql -header -sql "SELECT description FROM $bnprogdb WHERE name = '$progname'" $progdb
end

function _pp_category -a category
  printf "%s" (string upper (string sub -s 1 -l 1 $category[1]))(string sub -s 2 $category[1])
end

function _pp_prog_status -a prog
  if is-installed $prog
    set_color green
    printf "%s " $prog
    set_color normal
  else
    set_color red
    printf "%s " $prog
    set_color normal
  end
end

echo
set_color blue
echo "List of command line tools"
set_color normal
echo

for category in (_get_categories $progsfile)
  set_color yellow
  printf "\n%s\n\n" (_pp_category $category)
  set_color normal

  for prog in (_get_progs_by_category $progsfile $category)
    printf "%s " (_pp_prog_status $prog)
    _get_desc_by_progname $progsfile $prog
  end
end

functions -e _get_basedbname
functions -e _get_categories
functions -e _get_progs_by_category
functions -e _get_desc_by_progname
functions -e _pp_category
functions -e _pp_prog_status

end