forked from DieterDePaepe/windows-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwarp.bat
More file actions
94 lines (82 loc) · 2.3 KB
/
warp.bat
File metadata and controls
94 lines (82 loc) · 2.3 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
@ECHO OFF
REM Source found on https://github.com/DieterDePaepe/windows-scripts
REM Please share any improvements made!
REM Prevent environment variable pollution
setlocal
REM Folder where all links will end up
set WARP_REPO=%USERPROFILE%\.warp
REM Special bookmark that keeps track of last visited warping location
set WARP_LAST_VISITED=%WARP_REPO%\__LAST_VISITED__
REM Needed to calculate substring on command later on
set WARP_COMMAND_ISSUED=%1
IF [%1]==[/?] GOTO :help
IF [%1]==[/help] GOTO :help
IF [%1]==[--help] GOTO :help
IF [%1]==[] GOTO :last_visited
IF [%1]==[/create] GOTO :create
IF [%1]==[/list] GOTO :list
IF [%1]==[/remove] GOTO :remove
IF [%1]==[/window] GOTO :explorer
IF [%WARP_COMMAND_ISSUED:~0,1%]==[/] GOTO :unknowncommand
REM Command: warp <bookmark>
if not exist %WARP_REPO%\%1 (
ECHO Bookmark does not exist: "%1".
exit /b 1
)
set /p WARP_DIR=<%WARP_REPO%\%1
endlocal && pushd %WARP_DIR% && echo %WARP_DIR% > %WARP_LAST_VISITED% && GOTO :eof
:last_visited
set /p WARP_DIR=<%WARP_LAST_VISITED%
endlocal && pushd %WARP_DIR% && GOTO :eof
:explorer
IF [%2]==[] (
ECHO Missing bookmark name.
exit /b 1
)
set /p WARP_DIR=<%WARP_REPO%\%2
START explorer %WARP_DIR%
GOTO :eof
:create
IF [%2]==[] (
ECHO Missing bookmark name.
exit /b 1
)
if not exist %WARP_REPO%\NUL mkdir %WARP_REPO%
ECHO %cd% > %WARP_REPO%\%2
ECHO Created bookmark "%2".
GOTO :eof
:list
REM Delayed expansion needed to change variable inside the loop.
setlocal enabledelayedexpansion
for %%f in (%WARP_REPO%\*) do (
set /p LOCATION=<%%f
REM %%~nf = filename of loop variable %%f
echo %%~nf: !LOCATION!
)
setlocal disabledelayedexpansion
GOTO :eof
:unknowncommand
ECHO Unknown warp command: "%1".
exit /b 1
:remove
IF [%2]==[] (
ECHO Missing bookmark name.
exit /b 1
)
if not exist %WARP_REPO%\%2 (
ECHO Bookmark does not exist: "%2".
exit /b 1
)
del %WARP_REPO%\%2
GOTO :eof
:help
ECHO Create or navigate to folder bookmarks.
ECHO.
ECHO warp /? Display this help.
ECHO warp [bookmark] Navigate to an existing bookmark.
ECHO warp Navigate to last visited bookmark.
ECHO warp /create [bookmark] Create a new bookmark with the given name.
ECHO warp /list List existing bookmarks.
ECHO warp /remove [bookmark] Remove an existing bookmark.
ECHO warp /window [bookmark] Open an existing bookmark in explorer.
ECHO.