aboutsummaryrefslogtreecommitdiffstats
path: root/.w3m/cgi-bin/restore_session.cgi
blob: aa0ba41a7e0d486c8f67b6c1e7a02ba558f18bbe (plain) (blame)
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
#!/usr/bin/env sh
# AUTHOR: gotbletu (@gmail|twitter|youtube|github|lbry)
#         https://www.youtube.com/user/gotbletu
# DESC:   generate a script for your last w3m session then you can run script to restore all urls in new tabs
# DEMO:   https://youtu.be/qYhNJ3itqWw
# DEPEND: coreutils gawk
# CLOG:   2021-04-17 first draft, no option to jump to tab 1 at the moment
# REQD:   1. Allow executable permissions and put script in ~/.w3m/cgi-bin/restore_session.cgi 
#
#         2. Add binding to ~/.w3m/keymap
#
#             ############################ Quit with confirmation request (QUIT)
#             keymap  :q  QUIT
#             keymap  ZZ  QUIT
#             ############################ Quit at once (EXIT)
#             keymap  ZQ  EXIT
#             ############################ Quit at once and save session
#             keymap  Q       COMMAND     "EXTERN 'echo %s > ~/.w3m/RestoreSession.txt' ; NEXT_TAB ; EXTERN 'echo %s >> ~/.w3m/RestoreSession.txt' ; NEXT_TAB ; EXTERN 'echo %s >> ~/.w3m/RestoreSession.txt' ; NEXT_TAB ; EXTERN 'echo %s >> ~/.w3m/RestoreSession.txt' ; NEXT_TAB ; EXTERN 'echo %s >> ~/.w3m/RestoreSession.txt' ; NEXT_TAB ; EXTERN 'echo %s >> ~/.w3m/RestoreSession.txt' ; NEXT_TAB ; EXTERN 'echo %s >> ~/.w3m/RestoreSession.txt' ; NEXT_TAB ; EXTERN 'echo %s >> ~/.w3m/RestoreSession.txt' ; NEXT_TAB ; EXTERN 'echo %s >> ~/.w3m/RestoreSession.txt' ; NEXT_TAB ; EXTERN 'echo %s >> ~/.w3m/RestoreSession.txt' ; NEXT_TAB ; EXTERN 'echo %s >> ~/.w3m/RestoreSession.txt' ; NEXT_TAB ; EXTERN 'echo %s >> ~/.w3m/RestoreSession.txt' ; NEXT_TAB ; EXTERN 'echo %s >> ~/.w3m/RestoreSession.txt' ; NEXT_TAB ; EXTERN 'echo %s >> ~/.w3m/RestoreSession.txt' ; NEXT_TAB ; EXTERN 'echo %s >> ~/.w3m/RestoreSession.txt' ; NEXT_TAB ; EXTERN 'echo %s >> ~/.w3m/RestoreSession.txt' ; NEXT_TAB ; EXTERN 'echo %s >> ~/.w3m/RestoreSession.txt' ; NEXT_TAB ; EXTERN 'echo %s >> ~/.w3m/RestoreSession.txt' ; NEXT_TAB ; EXTERN 'echo %s >> ~/.w3m/RestoreSession.txt' ; NEXT_TAB ; EXTERN 'echo %s >> ~/.w3m/RestoreSession.txt' ; NEXT_TAB ; EXTERN 'echo %s >> ~/.w3m/RestoreSession.txt' ; NEXT_TAB ; EXTERN 'echo %s >> ~/.w3m/RestoreSession.txt' ; NEXT_TAB ; EXTERN 'echo %s >> ~/.w3m/RestoreSession.txt' ; NEXT_TAB ; EXTERN 'echo %s >> ~/.w3m/RestoreSession.txt' ; NEXT_TAB ; EXTERN 'echo %s >> ~/.w3m/RestoreSession.txt' ; NEXT_TAB ; EXTERN 'echo %s >> ~/.w3m/RestoreSession.txt' ; NEXT_TAB ; EXTERN 'echo %s >> ~/.w3m/RestoreSession.txt' ; NEXT_TAB ; EXTERN 'echo %s >> ~/.w3m/RestoreSession.txt' ; NEXT_TAB ; EXTERN 'echo %s >> ~/.w3m/RestoreSession.txt' ; NEXT_TAB ; EXTERN 'echo %s >> ~/.w3m/RestoreSession.txt' ; READ_SHELL ~/.w3m/cgi-bin/restore_session.cgi ; EXIT"
#
#         3. Add to ~/.bashrc or ~/.zshrc $PATH variable
#               [ -d "$HOME/.w3m/bin" ] && PATH="$HOME/.w3m/bin:$PATH"
#
#         4. To load w3m with the last session
#               $ w3mlastsession

## ---------------------------------------------
mkdir -p "$HOME/.w3m/bin"
# location of generated script of last session
RESTORE_SESSSION="$HOME/.w3m/bin/w3mlastsession"
# add shell header
echo "#!/usr/bin/env sh" > "$RESTORE_SESSSION"
echo "torsocks w3m -graph \\" >> "$RESTORE_SESSSION"
# remove dupes without sorting, add -N flag at beginning and append trailing slash to each url
awk '!x[$0]++' "$HOME/.w3m/RestoreSession.txt" | while read -r line ; do echo "-N '$line' \\" >> "$RESTORE_SESSSION" ; done
echo "2>/dev/null" >> "$RESTORE_SESSSION"
chmod +x "$RESTORE_SESSSION"

## OUTPUT SCRIPT FILE EXAMPLE ~/.w3m/bin/w3mlastsession
## --------------------------------------------------
##  #!/usr/bin/env sh
##  w3m \
##  -N 'https://www.reddit.com/r/w3m/.mobile' \
##  -N 'https://www.reddit.com/r/commandline/.mobile' \
##  -N 'https://www.reddit.com/r/linux/.mobile' \
##  -N 'http://lite.cnn.com/en' \
##  -N 'https://raw.githubusercontent.com/tats/w3m/master/ChangeLog' \
##  -N 'https://github.com/gotbletu/shownotes' \
##  2>/dev/null
## --------------------------------------------------