update tools to include additional info in table

This commit is contained in:
Daylin Morgan 2022-01-22 16:47:19 -06:00
parent 5acfc464dc
commit b507082c2f
2 changed files with 60 additions and 11 deletions

View file

@ -1,9 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env bash
BIN_DIR=$HOME/bin
mkdir -p $BIN_DIR
YAMLDOC="$DOTFILES_DIR/info/tools.yml"
#colors #colors
MAGENTA=$(tput setaf 5) MAGENTA=$(tput setaf 5)
CYAN=$(tput setaf 6) CYAN=$(tput setaf 6)
@ -12,6 +8,15 @@ RED=$(tput setaf 1)
GREEN=$(tput setaf 2) GREEN=$(tput setaf 2)
NORMAL=$(tput sgr0) NORMAL=$(tput sgr0)
BIN_DIR=$HOME/bin
YAMLDOC="$DOTFILES_DIR/info/tools.yml"
INSTALL_YES=${GREEN}✓${NORMAL}
INSTALL_NO=${RED}✗${NORMAL}
# get current binary files
shopt -s nullglob
BINARY_FILES=($HOME/bin/*)
alias eget="eget --system linux/amd64" alias eget="eget --system linux/amd64"
post_download_install() { post_download_install() {
@ -54,6 +59,7 @@ eget_tool() {
deps_check() { deps_check() {
mkdir -p $BIN_DIR
if ! $(is-executable eget); then if ! $(is-executable eget); then
echo "I don't see eget on your path..." echo "I don't see eget on your path..."
read -p "Do you want to download it to ${BIN_DIR}? " -n 1 -r read -p "Do you want to download it to ${BIN_DIR}? " -n 1 -r
@ -72,26 +78,65 @@ deps_check() {
} }
get_days() {
install_date=$1
date_out=$(date -d @$1 +'%Y.%m.%d %R')
now=$(date +'%s')
days=$(((now - install_date) / 86400))
if ((days > 60)); then
echo "${RED}$date_out${NORMAL}"
elif ((days > 30)); then
echo "${YELLOW}$date_out${NORMAL}"
else
echo "$date_out"
fi
}
check_install() {
bin_name=$BIN_DIR/$1
if printf '%s\n' "${BINARY_FILES[@]}" | grep -Fxq "$bin_name"; then
modified=$(date -r $bin_name +'%s')
echo $(get_days $modified)
fi
}
list() { list() {
deps_check deps_check
user_len=$(yq e '.[] | .user ' $YAMLDOC | tail -n +2 | sort | uniq | awk '{print length}' | sort -nr | head -n 1) user_len=$(yq e '.[] | .user ' $YAMLDOC | tail -n +2 | sort | uniq | awk '{print length}' | sort -nr | head -n 1)
tool_len=$(yq e 'keys| .[]' $YAMLDOC | tail -n +2 | sort | uniq | awk '{print length}' | sort -nr | head -n 1) tool_len=$(yq e 'keys| .[]' $YAMLDOC | tail -n +2 | sort | uniq | awk '{print length}' | sort -nr | head -n 1)
table_width=$((user_len + tool_len + 4)) table_width=$(($user_len + $tool_len + 25))
cell_width=$((table_width / 2 - 2)) tool_cell=$(printf "%${tool_len}s" "")
cell=$(printf "%${cell_width}s" "") user_cell=$(printf "%${user_len}s" "")
echo "${YELLOW}Configured Tools${NORMAL}" echo "${CYAN}CONFIGURED TOOLS${NORMAL}"
printf "%${table_width}s\n" "" | tr ' ' = printf "%${table_width}s\n" "" | tr ' ' =
printf "${CYAN}tool${NORMAL} %s | ${CYAN}author${NORMAL}\n" "${cell:5}" printf \
"${CYAN}tool${NORMAL}%s | \
${CYAN}author${NORMAL}%s | \
${CYAN} install date${NORMAL}\n" \
"${tool_cell:4}" "${user_cell:6}"
printf "%${table_width}s\n" "" | tr ' ' - printf "%${table_width}s\n" "" | tr ' ' -
readarray tools < <(yq e 'keys | .[]' $YAMLDOC) readarray tools < <(yq e 'keys | .[]' $YAMLDOC)
#sort tools for readability #sort tools for readability
tools=($(echo "${tools[@]:1}" | tr ' ' '\n' | sort | uniq)) tools=($(echo "${tools[@]:1}" | tr ' ' '\n' | sort | uniq))
for tool in "${tools[@]}"; do for tool in "${tools[@]}"; do
user=$(key=$tool yq e 'explode(.) | .[env(key)].user' $YAMLDOC) user=$(key=$tool yq e 'explode(.) | .[env(key)].user' $YAMLDOC)
printf "${MAGENTA}%s${NORMAL}%s | ${GREEN}$user${NORMAL}\n" $tool "${cell:${#tool}}" bin_name=$(key=$tool yq e 'explode(.) | .[env(key)].to' $YAMLDOC)
[[ "$bin_name" == "null" ]] && bin_name=$tool
modified=$(check_install $bin_name)
! [[ -z "$modified" ]] && installed=$INSTALL_YES || installed=$INSTALL_NO
printf \
"${MAGENTA}%s${NORMAL}%s | \
${YELLOW}%s${NORMAL}%s | \
$installed $modified\n" \
$tool "${tool_cell:${#tool}}" \
$user "${user_cell:${#user}}"
done done

View file

@ -15,6 +15,7 @@ lsd:
user: Peltoche user: Peltoche
ripgrep: ripgrep:
user: BurntSushi user: BurntSushi
to: rg
fd: fd:
<<: *default <<: *default
user: sharkdp user: sharkdp
@ -29,6 +30,7 @@ bottom:
asset: x86_64-unknown-linux-gnu.tar.gz asset: x86_64-unknown-linux-gnu.tar.gz
user: ClementTsang user: ClementTsang
file: btm file: btm
to: btm
# git # git
lazygit: lazygit:
@ -36,6 +38,7 @@ lazygit:
cli: cli:
user: cli user: cli
asset: linux_amd64.tar.gz asset: linux_amd64.tar.gz
to: gh
glab: glab:
user: profclems user: profclems
asset: Linux_x86_64.tar.gz asset: Linux_x86_64.tar.gz
@ -54,6 +57,7 @@ fnm:
# editing # editing
neovim: neovim:
user: neovim user: neovim
to: nvim
sh: sh:
user: mvdan user: mvdan
to: shfmt to: shfmt