Last active
January 9, 2022 18:25
-
-
Save Efreak/c2fad032110e2b65dcf625c20f889a2f to your computer and use it in GitHub Desktop.
list packages installed via cargo with colored columns for package name, version, and installed binaries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
if [ "$1" = "csearch" ]; then shift; fi #remove subcommand if called via `cargo csearch` | |
c33=$'\033[33m' | |
c34=$'\033[34m' | |
c35=$'\033[35m' | |
c0=$'\033[0m' | |
list="$(cargo search $@)" | |
function colorize(){ | |
sed -E 's/^([^ ]+) = "([^"]+)"\s*\# /'"${c33}\1${c35}\t\2$c0\t/g" | |
} | |
function tablize(){ | |
column --table -s $'\t' -W 3 -c $((${COLUMNS:-80} + 6)) | |
} | |
function pager(){ | |
${PAGER:-less -R} | |
} | |
function listcrates(){ | |
echo "$list"|grep -vE '^\.\.\. and [0-9]+ crates more' | colorize | tablize | |
echo "$list"|grep -E '^\.\.\. and [0-9]+ crates more' | |
} | |
listcrates | pager |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
c33=$'\033[33m' | |
c34=$'\033[34m' | |
c35=$'\033[35m' | |
list="$(cargo install --list)" | |
function removesources(){ | |
sed -E 's/\s*[(].*?\/.*?[)]//g' | |
} | |
function mergelines(){ | |
awk ' | |
/^ / { # indented line | |
sub(/^ /, ", ") # trim leading whitespace | |
merged = merged $0 # join to previous lines | |
next | |
} | |
merged { # previous merged line exists? | |
print merged # print previous | |
} | |
{ # line starts with non-whitespace char. | |
merged = $0 # start new merged line | |
} | |
END { | |
print merged # print last merged line | |
}' |sed -E 's/^([^,]+), /\1/g' | |
# no, i dont't really know how to use awk. yes, this is shitty code. | |
} | |
function colorize(){ | |
sed -E 's/^([^ ]+) v([^\:]+)\:/'"${c33}\1|${c35}\2|${c34}/g" | |
} | |
function tablize(){ | |
column --table -s'|' | |
} | |
function pager(){ | |
${PAGER:-less -R} | |
} | |
echo "$list"$'\n\n'Total crates: $(echo "$list"|wc -l) | removesources | mergelines | colorize | tablize | pager |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes, this is shitty code.
The functions/pipes are because I fairly regularly make changes to the way it works, and this way I can leave out of modify things without removing them entirely.
Save as
cargo-installed
in ~/.local/bin or somewhere in path, chmod +x, and you can usecargo installed
Alternatively:
And then you can update via git. Not that I expect there will be many updates here...