2 # ---------------------------------------------------------------------------
3 # Multi-Phasic Applications: SquirrelJME
4 # Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 # Copyright (C) Multi-Phasic Applications <multiphasicapps.net>
6 # ---------------------------------------------------------------------------
7 # SquirrelJME is under the GNU General Public License v3, or later.
8 # For more information see license.txt.
9 # ---------------------------------------------------------------------------
10 # DESCRIPTION: Moves a file within the repository to another destination.
15 # Directory of this script
16 __exedir
="$(dirname -- "$0")"
21 echo "Usage: $0 [-x] (from...) (to)" 1>&2
22 echo " If there are multiple source files, to must be a dir." 1>&2
23 echo " -x Do nothing, just print what would be done."
28 while getopts "x" __arg
43 shift $
(($OPTIND - 1))
45 # Not enough arguments
52 # Destination file or directory
53 __dest
="$("$__exedir/lastarg.sh
" "$@
")"
55 # The number of files to consider
58 # Copy of multiple files, target cannot be a non-directory
59 #if [ "$__count" -gt 1 ] && [ ! -d "$__dest" ]
61 # echo "Destination '$__dest' is not a directory!" 1>&2
66 for __i
in $
(seq 1 $__count)
72 # Determine the target file name
73 if [ "$__count" -gt 1 ]
75 __target
="$__dest/$(basename -- "$__src")"
79 __target
="$__dest/$(basename -- "$__src")"
85 # Make relative for simpler handling
86 __rsrc
="$("$__exedir/relative.sh
" "$__src")"
87 __rtrg
="$("$__exedir/relative.sh
" "$__target")"
89 # Mark how the file is moving
91 echo " -> $__rtrg" 1>&2
93 # If the source is a directory, use directory move script
98 "$__exedir/dirmv.sh" "-x" "$__src" "$__target"
101 "$__exedir/dirmv.sh" "$__src" "$__target"
104 # Otherwise treat as normal file move/rename
106 __targetdir
="$(dirname -- "$__target")"
108 if [ ! -d "$__targetdir" ]
111 __rtd
="$("$__exedir/relative.sh
" "$__targetdir")"
112 echo " md $__rtd" 1>&2
115 # Not actually going to move anything
116 if [ "$__noop" != 0 ]
121 # Make target directory?
122 if [ "$__maketargetdir" != "0" ]
124 mkdir
-p "$__targetdir"
127 # Move fossil file first
128 if fossil
mv "$__src" "$__target" > /dev
/null
130 if ! mv "$__src" "$__target" > /dev
/null
132 echo " !! FAILED TO MOVE REGULAR FILE." 1>&2
135 echo " !! FAILED TO MOVE FOSSIL FILE." 1>&2