From: Ian Kelling Date: Thu, 26 Jun 2014 09:26:57 +0000 (-0700) Subject: fix edge case missing extglob X-Git-Url: https://iankelling.org/git/?a=commitdiff_plain;h=0e81e42e5faadf13bb6ef9fe6650f57cbce7422b;p=lnf fix edge case missing extglob --- diff --git a/lnf-function b/lnf-function index 1780c8e..daae096 100644 --- a/lnf-function +++ b/lnf-function @@ -22,9 +22,13 @@ replacing a file but not a directory. No ln option arguments are supported." shift fi + local reset_extglob=false + ! shopt extglob >/dev/null && reset_extglob=true + shopt -s extglob + local remove x - if type -P dircolors >/dev/null; then + if type -P trash-put >/dev/null; then remove=trash-put else remove="rm -rf" @@ -41,7 +45,7 @@ replacing a file but not a directory. No ln option arguments are supported." local oldcwd=$PWD cd "${!#}" # last arg for x in "${@:1:$(( $# - 1 ))}"; do # all but last arg - # remove any trailing slashes + # remove any trailing slashes, uses extglob x="${x%%+(/)}" # remove any leading directory components x="${x##*/}" @@ -54,5 +58,7 @@ replacing a file but not a directory. No ln option arguments are supported." elif [[ $# -eq 1 ]]; then [[ -e "${1##*/}" || -L "${1##*/}" ]] && $remove "${1##*/}" fi + + $reset_extglob && shopt -u extglob ln -s -- "$@" }