#!/bin/zsh # # zsh colors # autoload colors && colors # Proxy # proxy=$(systemctl list-sockets --quiet "*proxy*" | head -1 | cut -d' ' -f1) if [ -n "${proxy}" ]; then echo "${bg[yellow]}${fg[black]} Using proxy ${fg_bold[black]}${proxy} \n" export ALL_PROXY="${proxy}" fi # asdf, direnv, python & lastversion # # - https://github.com/dvershinin/lastversion # cd $(dirname $0) eval $(asdf exec direnv export zsh) # Print Age # function print_age { program=$1 echo "\n${bg[red]}${fg[black]}>>>> ${program} ${reset_color}" # Already installed # if (( ${+commands[$program]} )); then echo "\n${bg[cyan]} Installation Age ${reset_color}" prog_out=$(${program} -V) # Extract version from program's output current_version=$(lastversion format "${prog_out}") # Highlight program's version echo ${prog_out} | grep --colour=always -F "${current_version}" lsd -lh --date=relative =${program} fi echo } # Debian Package # function debian { program=$1 repository=$2 apt_name=${3:-$1} current_version="0.0.0" echo "\n${bg[red]}${fg[black]}>>>> ${program} ${reset_color}" # Already installed # if (( ${+commands[$program]} )); then echo "\n${bg[cyan]} Installed ${reset_color}" prog_out=$(${program} --version) # Extract version from program's output current_version=$(lastversion format "${prog_out}") # Highlight program's version echo ${prog_out} | grep --colour=always -F "${current_version}" \ls -lh =${program} fi # Repository # echo "\n${bg[cyan]} ${repository} ${reset_color}" # Retrieve latest repository version repo_version=$(lastversion ${repository} --newer-than ${current_version}) # Check last result code if [ $? -eq 0 ]; then echo "${fg[red]}${repo_version}${fg[cyan]} > ${current_version}${reset_color}\n" echo "${fg[cyan]}${repository}/releases/latest${reset_color}" lastversion ${repository} --assets --filter="." \ | rg --color=always --passthru --regexp="${filter}" else echo "${fg[green]}${repo_version}" fi echo -n ${reset_color} # Debian Package apt_list=$(apt list ${apt_name} 2>/dev/null) deb_version=$(lastversion format "${apt_list}" 2>/dev/null) if [ $? -eq 0 ]; then echo "\n${bg[cyan]} Debian package ${reset_color}" deb_version=$(lastversion "${deb_version}" --newer-than ${current_version}) if [ $? -eq 0 ]; then echo "${fg[red]}${deb_version} ${fg[cyan]} > ${current_version}${reset_color}\n" else echo "${fg[green]}${deb_version}" fi echo -n ${reset_color} fi echo } # Archive # function archive { program=$1 repository=$2 current_version=${3:-"0.0.0"} echo "\n${bg[red]}${fg[black]}>>>> ${program} ${reset_color}" # Already installed # if (( ${+commands[$program]} )); then echo "\n${bg[cyan]} Installed ${reset_color}" prog_out=$(${program} --version) # Extract version from program's output current_version=$(lastversion format "${prog_out} | head -1 )" 2>/dev/null) if [ -e ${current_version} ]; then current_version=$(lastversion format "${prog_out} | grep -o "version=[0-9.]\+")") fi # Highlight program's version echo ${prog_out} | grep --colour=always -F "${current_version}" \ls -lh =${program} fi # Repository # echo "\n${bg[cyan]} ${repository} ${reset_color}" # Retrieve latest repository version repo_version=$(lastversion ${repository} --newer-than ${current_version}) # Check last result code if [ $? -eq 0 ]; then echo "${fg[red]}${repo_version}${fg[cyan]} > ${current_version}${reset_color}\n" echo "${fg[cyan]}${repository}/releases/latest${reset_color}" lastversion ${repository} --assets --filter="." \ | rg --color=always --passthru --regexp="${filter}" else echo "${fg[green]}${repo_version}" fi echo ${reset_color} } ### filter='([^/]+amd64\.deb|\w+\.txt)$' debian bat 'https://github.com/sharkdp/bat' debian delta 'https://github.com/dandavison/delta' git-delta debian lsd 'https://github.com/lsd-rs/lsd' filter='(Linux_x86_64|\w*\.appimage$|\w+\.appimage\.\w+sum$|\w+\.txt$)' archive lazygit https://github.com/jesseduffield/lazygit archive nvim https://github.com/neovim/neovim print_age nnn # Fonts setopt nullglob fonts=( $(echo /opt/fonts/**/*NerdFont* $HOME/.fonts/**/*NerdFont*) ) if (( ${#fonts} )); then font_version=$(lastversion format "$(strings ${fonts[1]} | grep -o 'Nerd Fonts [0-9.]\+')") fi filter='((JetBrainsMono|NerdFontsSymbolsOnly)\.tar\.xz|\w+\.txt)$' archive "Nerd Fonts" https://github.com/ryanoasis/nerd-fonts "${font_version}"