Posted to tcl by dbohdan at Sun Nov 08 14:45:26 GMT 2020view raw

  1. #! /usr/bin/env tclsh
  2. #
  3. # A database of Ubuntu packages I use. To install:
  4. # $ apt install $(./packages [tag ...])
  5. # Requires: Tcl 8.6 or later.
  6. #
  7. # Copyright (c) 2020 D. Bohdan.
  8. #
  9. # Permission to use, copy, modify, and distribute this software for any
  10. # purpose with or without fee is hereby granted, provided that the above
  11. # copyright notice and this permission notice appear in all copies.
  12. #
  13. # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  14. # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  15. # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  16. # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  17. # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  18. # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  19. # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  20.  
  21. set packages {
  22.  
  23. apache2-utils benchmark network
  24. asciidoc converter HTML markup
  25. audacious audio player
  26. audacity audio editor
  27. autoconf dev
  28. autogen dev
  29. automake dev
  30. bat text viewer
  31. bless GUI editor hex
  32. borgbackup backup
  33. bsdgames game rot13 toy
  34. build-essential C dev
  35. calibre ebook reader
  36. cloc dev
  37. cmake C dev
  38. cmark converter HTML markup
  39. cpulimit hardware
  40. critcl C dev Tcl
  41. curl client network
  42. dos2unix converter text
  43. dosbox emulator
  44. doublecmd-qt file-manager
  45. entr automation
  46. ethtool network hardware
  47. exiftool image metadata
  48. expect dev Tcl
  49. fdupes duplicate
  50. feh image viewer
  51. ffmpeg converter multitool video
  52. findimagedupes duplicate
  53. flac audio codec
  54. fonts-open-sans font
  55. fortune-mod toy
  56. gdb debugging dev
  57. geeqie image viewer
  58. genisoimage filesystem ISO
  59. gifsicle image optimizer
  60. gimp editor image
  61. git dev
  62. gnupg2 cryptography
  63. gparted disk
  64. graphicsmagick automation converter editor image multitool
  65. gsmartcontrol disk
  66. gxkb GUI keyboard
  67. hardinfo GUI hardware system-info
  68. hddtemp hardware monitoring
  69. htop monitoring
  70. hwinfo hardware system-info
  71. icewm window-manager
  72. id3 audio editor metadata
  73. id3v2 audio editor metadata
  74. imagemagick automation converter editor image multitool
  75. iotop disk monitoring
  76. jq interpreter JSON
  77. keepassx GUI password
  78. lftp client FTP
  79. libaugeas-dev dev
  80. liblz4-tool compression
  81. lm-sensors monitoring
  82. lrzip compression
  83. lxd container
  84. lz4 compression
  85. lzop compression
  86. magic-wormhole network
  87. mc file-manager
  88. meld comparison GUI text
  89. mercurial dev
  90. minify CSS optimizer
  91. mosh network remote
  92. mpv player video
  93. neovim editor text
  94. netcat multitool network
  95. netpbm automation converter editor image multitool
  96. nfs-common network NFS
  97. nmap network security
  98. optipng image optimizer
  99. opus-tools audio codec
  100. pcmanfm-qt file-manager GUI
  101. pep8 dev Python
  102. pkg-config dev
  103. pngcrush image optimizer
  104. pngquant image optimizer
  105. postfix email server
  106. postgresql database
  107. pv monitoring
  108. pwgen password
  109. pylint dev Python
  110. python3-dev dev Python
  111. python3-more-itertools dev Python
  112. python3-pip dev Python
  113. python3-psutil dev Python
  114. python3-pytest dev Python
  115. python3-venv dev Python
  116. python3-wheel dev Python
  117. qdirstat system-info
  118. qterminal terminal-emulator
  119. rar compression
  120. rclone multitool network
  121. redis-server database
  122. remmina GUI remote
  123. remmina-plugin-vnc GUI remote VNC
  124. rename file
  125. rlwrap TUI
  126. scrot GUI image screenshot
  127. sed interpreter text
  128. shellcheck dev
  129. slugify converter text
  130. smartmontools disk hardware system-info
  131. smbclient client network
  132. sqlite3 database
  133. squashfs-tools filesystem
  134. tcl dev Tcl
  135. tcl-dev C dev Tcl
  136. tcl-doc dev Tcl
  137. tcl-itcl4 dev Tcl
  138. tcl-thread dev Tcl
  139. tcl-tls dev network Tcl
  140. tcl-vfs dev Tcl
  141. tcl8.6-tdbc-postgres dev Tcl
  142. tcl8.6-tdbc-sqlite3 dev Tcl
  143. tclcurl dev network Tcl
  144. tcllib dev Tcl
  145. tcllib-critcl dev Tcl
  146. tclx8.4 dev Tcl
  147. tclx8.4-doc dev Tcl
  148. tdom dev Tcl
  149. tesseract-ocr converter image OCR text
  150. testdisk disk hardware
  151. thunderbird client email
  152. tidy converter HTML optimizer
  153. tk dev Tcl Tk
  154. tk-doc dev Tcl Tk
  155. tk-table dev Tcl Tk
  156. tklib dev Tcl Tk
  157. transmission network Torrent
  158. tree file
  159. ttf-mscorefonts-installer font
  160. udiskie disk GUI
  161. unicode-screensaver screensaver
  162. uptimed monitoring
  163. upx-ucl compression dev
  164. valgrind debugging dev
  165. vim editor text
  166. webp codec image
  167. whois network
  168. wine emulation
  169. workrave ergonomics GUI
  170. xclip GUI
  171. xdotool automation GUI
  172. xkbset GUI keyboard
  173. xml2 converter XML
  174. xscreensaver screensaver
  175. xscreensaver-data-extra screensaver
  176. xscreensaver-screensaver-bsod screensaver
  177. xsensors GUI hardware monitoring
  178. yacc dev
  179. zfsutils-linux disk filesystem
  180. zpaq backup compression
  181. zstd compression
  182. zzuf debugging dev
  183.  
  184. }
  185.  
  186.  
  187. proc main {packages argv} {
  188. if {$argv in {-h -help --help -? /?}} {
  189. set me [file tail [info script]]
  190. puts stderr "usage: $me"
  191. puts stderr " $me \"tags\""
  192. puts stderr " $me tag \[tag ...\]"
  193. exit 0
  194. }
  195.  
  196. set byTag [parse-pkg-list $packages]
  197.  
  198. puts [switch -- $argv {
  199. tags { lsort -nocase [dict keys $byTag] }
  200. default { pkgs-with-tags $byTag $argv }
  201. }]
  202. }
  203.  
  204.  
  205. proc parse-pkg-list packages {
  206. set lines [split [string trim $packages] \n]
  207. foreach line $lines {
  208. set pkg [lindex $line 0]
  209. foreach tag [lrange $line 1 end] {
  210. dict lappend byTag [string tolower $tag] $pkg
  211. }
  212. }
  213.  
  214. return $byTag
  215. }
  216.  
  217.  
  218. # $tags must be a list of "tag" or "-tag". The latter removes packages with
  219. # the tag from the selection.
  220. proc pkgs-with-tags {byTag tags} {
  221. set tag [lindex $tags 0]
  222. set found [if {[llength $tags] == 0 || [regexp ^-(.*)$ $tag _ tag]} {
  223. lsort [concat {*}[dict values $byTag]]
  224. } else {
  225. pkgs-with-tag $byTag $tag
  226. }]
  227.  
  228. foreach tag [lrange $tags 1 end] {
  229. set op intersection
  230. if {[regexp ^-(.*)$ $tag _ tag]} {
  231. set op difference
  232. }
  233.  
  234. set found [set::$op $found [pkgs-with-tag $byTag $tag]]
  235. }
  236.  
  237. return $found
  238. }
  239.  
  240.  
  241. proc pkgs-with-tag {byTag tag} {
  242. set tag [string tolower $tag]
  243.  
  244. if {![dict exists $byTag $tag]} {
  245. return {}
  246. }
  247.  
  248. dict get $byTag $tag
  249. }
  250.  
  251. namespace eval set {}
  252.  
  253. proc set::intersection {a b} {
  254. lmap x $a {
  255. if {$x ni $b} continue
  256. set x
  257. }
  258. }
  259.  
  260.  
  261. proc set::difference {a b} {
  262. lmap x $a {
  263. if {$x in $b} continue
  264. set x
  265. }
  266. }
  267.  
  268.  
  269. main $packages $argv