-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstash.bat
More file actions
54 lines (47 loc) · 1.39 KB
/
stash.bat
File metadata and controls
54 lines (47 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
@REM Move files/dirs passed as input between '__staged' and '__unstaged'.
@REM
@REM Usage:
@REM stash.bat <file/dir> [<file/dir> ...]
@REM
@REM Example:
@REM stash.bat file1 file2 dir1
@REM
@REM This will move file1, file2, and dir1 from '__staged' to '__unstaged', or vice versa.
@REM
@REM Note:
@REM If the file/dir is not under '__staged' or '__unstaged', it will be ignored.
@REM
@echo off
setlocal enabledelayedexpansion enableextensions
set "staged=__staged\"
set "unstaged=__unstaged\"
set "files=%*"
for %%i in (%files%) do (
set "file=%%~fi"
if "!file:~-1!"=="\" set "file=!file:~0,-1!"
set "wo_mod=!file:%staged%=!"
set "wo_usg=!file:%unstaged%=!"
if not "!wo_mod!"=="!%file!" (
set "file_dest=!file:%staged%=%unstaged%!"
) else if not "!wo_usg!"=="!file!" (
set "file_dest=!file:%unstaged%=%staged%!"
) else (
echo "!file! is not under '__staged' or '__unstaged'."
exit /b
)
if exist "%file_dest%" (
set /p "confirm=!file_dest! already exists."
exit /b
)
for %%j in ("!file_dest!") do set "dir_dest=%%~dpj"
mkdir "!dir_dest!" 2>nul
if exist "!file!\" (
robocopy "!file!" "!file_dest!" /move
) else (
for %%j in ("!file!") do (
set "dir_source=%%~dpj"
set "file=%%~nxj"
)
robocopy "!dir_source:~0,-1!" "!dir_dest:~0,-1!" "!file!" /mov
)
)