Created
December 29, 2024 18:10
-
-
Save toniher/a118c47e7fb0572bce8711f4209420ff to your computer and use it in GitHub Desktop.
Convenient script for installing packages in the file system, and a counterpart back-up one as well. They can be stored in .local/bin
This file contains hidden or 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 | |
npm list --global --parseable --depth=0 | perl -lane 'if ( $_=~/node_modules\/(\S+)/ ) { print $1; }' >"$HOME/.config/npm.backup" | |
pip freeze >"$HOME/.config/requirements.backup" | |
cargo install --list | perl -lane 'if ( $_=~/^(\S+)/ ) { print $1; }' >"$HOME/.config/cargo.backup" |
This file contains hidden or 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 | |
FILE=${1:-cargo} | |
function read_file_lines { | |
local file_path="${HOME}/.config/${FILE}.txt" | |
while IFS= read -r line; do | |
echo "$line" | |
eval "$PROGRAM $line" | |
done <"$file_path" | |
} | |
case "$FILE" in | |
cargo) | |
PROGRAM="cargo install" | |
read_file_lines | |
;; | |
npm) | |
PROGRAM="npm install -g" | |
read_file_lines | |
;; | |
requirements) | |
pip install --upgrade -r "$HOME/.config/${FILE}.txt" | |
;; | |
*) | |
echo "Unknown file type. Choose cargo, npm or requirements" | |
exit 1 | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment