From 9a749aa8ab8564e4a6a024b6e14480b5cf9b4ea1 Mon Sep 17 00:00:00 2001 From: Fini Jastrow Date: Fri, 22 Apr 2022 07:45:16 +0200 Subject: [PATCH] install.sh: Add uninstall command [why] Maybe people would like to uninstall the fonts installed with the script. In fact the uninstall could already be acieved by giving the --clean option and installing no new font. Well, apart from the fact that the scripts prevents runs with no installed font. And then the user must specify the same installpath that has been used for the install, which is a bit tedious. [how] Add new command '--remove' (with no short option). Make -L / --list option a dry-run option for --remove. Uninstall both possible installpaths. Fixes: #407 Signed-off-by: Fini Jastrow --- install.sh | 61 +++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 44 insertions(+), 17 deletions(-) diff --git a/install.sh b/install.sh index a77369ae4d..218e768899 100755 --- a/install.sh +++ b/install.sh @@ -1,11 +1,12 @@ #!/usr/bin/env bash # Install Nerd Fonts -__ScriptVersion="0.3" +__ScriptVersion="0.4" # Default values for option variables: quiet=false mode="copy" clean=false +dry=false extension="otf" patches=("Complete") # There are no other variants then Complete anymore compat=() @@ -14,7 +15,7 @@ installpath="user" # Usage info usage() { cat << EOF -Usage: ./install.sh [-q -v -h] [[--copy | --link] --clean | --list] +Usage: ./install.sh [-q -v -h] [[--copy | --link] --clean | --list | --remove] [--use-single-width-glyphs] [--windows] [--otf | --ttf] [--install-to-user-path | --install-to-system-path ] [FONT...] @@ -32,6 +33,10 @@ General options: -C, --clean Recreate the root Nerd Fonts target directory (clean out all previous copies or symlinks). + --remove Remove all Nerd Fonts (that have been installed + with this script). + Can be combined with -L for a dry run. + -s, --use-single-width-glyphs Install single-width glyphs variants. -w, --windows Install with limited internal font names. @@ -59,7 +64,8 @@ while getopts "$optspec" optchar; do h) usage; exit 0;; c) mode="copy";; l) mode="link";; - L) mode="list";; + L) dry=true + [ "$mode" != "remove" ] && mode="list";; C) clean=true;; s) compat=( "${compat[@]}" "Nerd Font*Mono" );; w) compat=( "${compat[@]}" "Windows Compatible" );; @@ -76,7 +82,9 @@ while getopts "$optspec" optchar; do help) usage; exit 0;; copy) mode="copy";; link) mode="link";; - list) mode="list";; + list) dry=true + [ "$mode" != "remove" ] && mode="list";; + remove) mode="remove";; clean) clean=true;; use-single-width-glyphs) compat=( "${compat[@]}" "Nerd Font*Mono" );; windows) compat=( "${compat[@]}" "Windows Compatible" );; @@ -206,20 +214,21 @@ done # Get target root directory if [[ $(uname) == 'Darwin' ]]; then # MacOS - if [[ "system" == "$installpath" ]]; then - font_dir="/Library/Fonts" - else - font_dir="$HOME/Library/Fonts" - fi + sys_font_dir="/Library/Fonts" + usr_font_dir="$HOME/Library/Fonts" else # Linux - if [[ "system" == "$installpath" ]]; then - font_dir="/usr/local/share/fonts" - else - font_dir="$HOME/.local/share/fonts" - fi + sys_font_dir="/usr/local/share/fonts" + usr_font_dir="$HOME/.local/share/fonts" +fi +sys_font_dir="${sys_font_dir}/NerdFonts" +usr_font_dir="${usr_font_dir}/NerdFonts" + +if [[ "system" == "$installpath" ]]; then + font_dir="${sys_font_dir}" +else + font_dir="${usr_font_dir}" fi -font_dir="${font_dir}/NerdFonts" # # Take the desired action @@ -252,12 +261,30 @@ case $mode in ;; esac;; + remove) + if [[ "true" == "$dry" ]]; then + echo "Dry run. Would issue these commands:" + [ "$quiet" = false ] && echo rm -rfv "$sys_font_dir" "$usr_font_dir" + [ "$quiet" = true ] && echo rm -rf "$sys_font_dir" "$usr_font_dir" + else + echo DOING STUFF + [ "$quiet" = false ] && rm -rfv "$sys_font_dir" "$usr_font_dir" + [ "$quiet" = true ] && rm -rf "$sys_font_dir" "$usr_font_dir" + fi + font_dir="$sys_font_dir $usr_font_dir" + ;; + esac # Reset font cache on Linux if [[ -n $(command -v fc-cache) ]]; then - [ "$quiet" = false ] && fc-cache -vf "$font_dir" - [ "$quiet" = true ] && fc-cache -f "$font_dir" + if [[ "true" == "$dry" ]]; then + [ "$quiet" = false ] && echo fc-cache -vf "$font_dir" + [ "$quiet" = true ] && echo fc-cache -f "$font_dir" + else + [ "$quiet" = false ] && fc-cache -vf "$font_dir" + [ "$quiet" = true ] && fc-cache -f "$font_dir" + fi case $? in [0-1]) # Catch fc-cache returning 1 on a success