💾 Archived View for splint.rs › gen › little_programs.gmi captured on 2023-04-19 at 22:58:07. Gemini links have been rewritten to link to archived content
-=-=-=-=-=-=-
Show file info.
stat little_programs.md
File: little_programs.md Size: 5277 Blocks: 16 IO Block: 4096 regular file Device: 805h/2053d Inode: 6554954 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 1000/ ghost) Gid: ( 1000/ ghost) Access: 2022-02-21 20:48:37.840867061 +0100 Modify: 2022-02-21 20:41:44.774001797 +0100 Change: 2022-02-21 20:41:44.778001768 +0100 Birth: 2022-02-21 20:41:44.774001797 +0100
Show what type of file something is.
type /tmp/*
amfora_temp: directory dbus-U00gxuKxNT: socket scoped_dirNCvmsA: directory serverauth.ELLhbMvz60: X11 Xauthority data
Watch a command for changes in the output.
watch cat /proc/net/arp
Or watch how much of the filesystem is free.
watch df -h
Let a command run for a limited amount of time:
timeout 3 htop
Useful if you want a process to automatically run, but it's in danger of stopped, and asking you some questions. For example, if you want to 'apt update', then that might work, but it might stall until you answer a question. You can't really answer that question if the thing is running as part of a script, so to avoid having it hang, just cancel it after 10 minutes (or some time longer than an upgrade might take).
NB: When using sudo, the timeout command will apply to sudo itself, so best to run after the sudo, e.g.
sudo timeout 10m apt upgrade -y
This may still lock the database, but at least you won't have a bunch of useless scripts building up.
Count the lines of code in a repository.
cloc project
59 text files. 48 unique files. 18 files ignored. github.com/AlDanial/cloc v 1.92 T=0.05 s (879.2 files/s, 181191.9 lines/s) ------------------------------------------------------------------------------- Language files blank comment code ------------------------------------------------------------------------------- C++ 7 934 255 4916 C/C++ Header 8 103 106 724 TeX 7 113 16 660 CSV 8 0 0 654 Python 4 59 49 652 Markdown 3 187 0 220 Bourne Shell 4 34 14 121 make 5 0 0 49 YAML 1 0 0 15 CMake 1 3 5 3 ------------------------------------------------------------------------------- SUM: 48 1433 445 8014 -------------------------------------------------------------------------------
This can be useful for an overview of a project. The program is also great at counting actual lines of code, rather than just lines. The following contains 6 lines:
ls -t | \ sort -r > list cat < list
cloc will recognize blank lines are not lines of code, and recognize joined lines of code as separate.
This outputs disk usage with a nice display.
duf -only local
╭────────────────────────────────────────────────────────────────────╮ │ 2 local devices │ ├────────────┬────────┬────────┬────────┬────────┬──────┬────────────┤ │ MOUNTED ON │ SIZE │ USED │ AVAIL │ USE% │ TYPE │ FILESYSTEM │ ├────────────┼────────┼────────┼────────┼────────┼──────┼────────────┤ │ / │ 117.6G │ 63.7G │ 47.8G │ 54.2% │ ext4 │ /dev/sda5 │ │ /boot/efi │ 602.1M │ 152.0K │ 602.0M │ 0.0% │ vfat │ /dev/sda6 │ ╰────────────┴────────┴────────┴────────┴────────┴──────┴────────────╯
Output a message to your desktop.
sleep 8m && notify-send Tea 'water boiling' & disown
This will output a notification to finish making tea in 8 minutes. The 'disown' statement tells the terminal to leave the process running, even without the terminal.
This gives you the ability to type through a list to select an item.
Try this for a start:
ls | fzy
ghost [ ~ ] └─►─ ls | fzy > Distros LK Mail Projects VMs arc dl gollum img kn
Okay - not terribly impressive so far. But we can do things with the output.
cd $(find ~/* -type d | fzy)
Now we can find anywhere in the home directory and change directory there instantly. Or open any nearby file in vim:
alias vf='vim "$(find -type f | fzy)"'
vf
Now you can just type in vf and type the name of a file you want to edit, and fzy will find it for you.
Output a summary of a Git.
$$$$$$$$$$$$$$$$$$$$ Malin Freeborn ~ git version 2.35.1 $$ $$$$ $$$ $ ----------------------------------- $ $$ $$ $$$$$ $$$$ $$$ Project: core (3 branches, 6 tags) $ $$$ $$$ $$$$$ $$$ $$$ HEAD: 115ba07 (dev, origin/dev) $ $$$ $$ $$ $$ $$$$ Pending: 20+- $ $$$ $$$ $$$ $$ $ $$$$ Version: 0.6 $$$$ $$$ $$$ $$$ $$$$$ Created: 2 years ago $$$$ $$$ $$$ $$$ $$$$$ Language: TeX (100.0 %) $$$$ $$$ $$$$$$ $$$$ Authors: 100% Malin Freeborn 2188 $$$$ $$$ $$ $$$$ $ $$$$ 0% Vladar4 1 $$$$ $$$ $$$ $$ $$$ Last change: a week ago $$$$ $$$ $$ $$$ $$$ $$$ Repo: https://gitlab.com/bindrpg/core $$$$ $$$ $$$$ $$$$ $$ Commits: 2189 $$$ $ $$$ $$$ $ Lines of code: 8416 $$$$$$$$ $$$$ $$$$$$$$ Size: 11.22 MiB (78 files) $$$$$$$$ $$$ $$$$$$$$ License: GPL-3.0-only $$$$$$$ $$$$$$$$ $$$$$$$$$$$$$$$$$$$$