mirror of
https://github.com/natelandau/shell-scripting-templates.git
synced 2025-11-10 14:13:45 -05:00
_makeSymlink_: add quiet mode
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
_listFiles_() {
|
_listFiles_() {
|
||||||
# DESC: Find files in a directory. Use either glob or regex
|
# DESC: Find files in a directory. Use either glob or regex
|
||||||
# ARGS: $1 (Required) - 'g|glob' or 'r|regex'
|
# ARGS: $1 (Required) - 'g|glob' or 'r|regex'
|
||||||
@@ -326,8 +325,9 @@ _makeSymlink_() {
|
|||||||
# ARGS: $1 (Required) - Source file
|
# ARGS: $1 (Required) - Source file
|
||||||
# $2 (Required) - Destination
|
# $2 (Required) - Destination
|
||||||
# $3 (Optional) - Backup directory for files which may be overwritten (defaults to 'backup')
|
# $3 (Optional) - Backup directory for files which may be overwritten (defaults to 'backup')
|
||||||
# OPTS: -n - Do not create a backup if target already exists
|
# OPTS: -c - Only report on new/changed symlinks. Quiet when nothing done.
|
||||||
# -s - Use sudo when removing old files to make way for new symlinks
|
# -n - Do not create a backup if target already exists
|
||||||
|
# -s - Use sudo when removing old files to make way for new symlinks
|
||||||
# OUTS: None
|
# OUTS: None
|
||||||
# USAGE: _makeSymlink_ "/dir/someExistingFile" "/dir/aNewSymLink" "/dir/backup/location"
|
# USAGE: _makeSymlink_ "/dir/someExistingFile" "/dir/aNewSymLink" "/dir/backup/location"
|
||||||
# NOTE: This function makes use of the _execute_ function
|
# NOTE: This function makes use of the _execute_ function
|
||||||
@@ -336,11 +336,13 @@ _makeSymlink_() {
|
|||||||
local OPTIND=1
|
local OPTIND=1
|
||||||
local backupOriginal=true
|
local backupOriginal=true
|
||||||
local useSudo=false
|
local useSudo=false
|
||||||
|
local ONLY_SHOW_CHANGED=false
|
||||||
|
|
||||||
while getopts ":nNsS" opt; do
|
while getopts ":cCnNsS" opt; do
|
||||||
case $opt in
|
case $opt in
|
||||||
n | N) backupOriginal=false ;;
|
n | N) backupOriginal=false ;;
|
||||||
s | S) useSudo=true ;;
|
s | S) useSudo=true ;;
|
||||||
|
c | C) ONLY_SHOW_CHANGED=true ;;
|
||||||
*)
|
*)
|
||||||
{
|
{
|
||||||
error "Unrecognized option '$1' passed to _makeSymlink_" "$LINENO"
|
error "Unrecognized option '$1' passed to _makeSymlink_" "$LINENO"
|
||||||
@@ -403,7 +405,10 @@ _makeSymlink_() {
|
|||||||
o="$(realpath "${d}")"
|
o="$(realpath "${d}")"
|
||||||
|
|
||||||
[[ ${o} == "${s}" ]] && {
|
[[ ${o} == "${s}" ]] && {
|
||||||
if [ "${DRYRUN}" == true ]; then
|
|
||||||
|
if [ ${ONLY_SHOW_CHANGED} == true ]; then
|
||||||
|
debug "Symlink already exists: ${s} → ${d}"
|
||||||
|
elif [ "${DRYRUN}" == true ]; then
|
||||||
dryrun "Symlink already exists: ${s} → ${d}"
|
dryrun "Symlink already exists: ${s} → ${d}"
|
||||||
else
|
else
|
||||||
info "Symlink already exists: ${s} → ${d}"
|
info "Symlink already exists: ${s} → ${d}"
|
||||||
|
|||||||
Reference in New Issue
Block a user