diff --git a/w3m_macros.md b/w3m_macros.md index ea67c29..82a8b39 100644 --- a/w3m_macros.md +++ b/w3m_macros.md @@ -8,23 +8,32 @@ Using macros automate toggling settings like images display or table borders on w3m ### configuration - vim ~/.w3m/keymap + $EDITOR ~/.w3m/keymap + # for more help on options + # $ w3m -show-option + # leader key = \ - keymap \\\t COMMAND "SET_OPTION display_borders=toggle ; RESHAPE" + keymap \\\? COMMAND "HELP; SEARCH ^User-Defined; CENTER_V" # show user custom hotkeys binding + keymap \\\f COMMAND "HELP; SEARCH ^Input Line Editing Mode; CENTER_V" # show field hotkeys binding + keymap \\\c COMMAND "SET_OPTION color=toggle ; RESHAPE" + keymap \\\u COMMAND "SET_OPTION mark_all_pages=toggle ; RELOAD" # Treat URL-like strings as links in all pages (convert text to url) + keymap \\\l COMMAND "SET_OPTION display_link_number=toggle ; SET_OPTION show_lnum=toggle ; RESHAPE" # toggle hinting mode / line numbers + keymap \\\h COMMAND "SET_OPTION display_link_number=toggle ; RESHAPE" # toggle hinting mode + keymap \\\n COMMAND "SET_OPTION show_lnum=toggle ; RESHAPE" # toggle line numbers + keymap \\\b COMMAND "SET_OPTION display_borders=toggle ; RESHAPE" keymap \\\i COMMAND "SET_OPTION display_image=toggle ; RELOAD" - keymap \\\e COMMAND "SET_OPTION user_agent='' ; RELOAD" - keymap \\\a COMMAND "SET_OPTION user_agent='Opera/9.80 (S60; SymbOS; Opera Mobi/SYB-1107071606; U; en) Presto/2.8.149 Version/11.10' ; RELOAD" + keymap \\\e COMMAND "SET_OPTION user_agent='' ; RELOAD" # empty user agent + keymap \\\A COMMAND "SET_OPTION user_agent='Opera/9.80 (S60; SymbOS; Opera Mobi/SYB-1107071606; U; en) Presto/2.8.149 Version/11.10' ; RELOAD" keymap C-t COMMAND "TAB_GOTO https://duckduckgo.com/lite/; NEXT_LINK; GOTO_LINK" keymap t COMMAND "TAB_GOTO https://duckduckgo.com/lite/; NEXT_LINK; GOTO_LINK" keymap sg COMMAND "TAB_GOTO https://google.com; GOTO_LINE 6; NEXT_LINK; GOTO_LINK" keymap sx COMMAND "TAB_GOTO https://stackexchange.com; GOTO_LINE 7; NEXT_LINK; GOTO_LINK" - keymap \\\? COMMAND "HELP; SEARCH User-Defined; CENTER_V" keymap \\\m COMMAND "SHELL 'man w3m'" ### references - https://youtu.be/lL73xWsaJP8 -- https://raw.githubusercontent.com/felipesaa/A-vim-like-firefox-like-configuration-for-w3m/master/documentation/functions.txt +- https://github.com/felipesaa/A-vim-like-firefox-like-configuration-for-w3m/blob/master/documentation/functions.txt - https://vitalyparnas.com/posts/2018/08/on-w3m/ - https://vitalyparnas.com/posts/2019/07/w3m-redux/ - https://vitalyparnas.com/guides/w3m/ diff --git a/w3m_plugins/cgi-bin/fzf_surfraw.cgi b/w3m_plugins/cgi-bin/fzf_surfraw.cgi index 27fee3c..80c785f 100755 --- a/w3m_plugins/cgi-bin/fzf_surfraw.cgi +++ b/w3m_plugins/cgi-bin/fzf_surfraw.cgi @@ -3,51 +3,40 @@ # https://www.youtube.com/user/gotbletu # DESC: interactive surfraw smart prefix search engine # DEMO: https://youtu.be/p5NZb8f8AHA | updated https://youtu.be/0j3pUfZjCeQ -# DEPEND: surfraw fzf gawk coreutils grep (xsel or tmux) -# RQMTS: 1. allow permissions and put goto_* scripts in /usr/lib/w3m/cgi-bin/ -# 2. allow permissions and put fzf_surfraw.cgi any where you like e.g ~/.w3m/cgi-bin/ -# 3. $EDITOR ~/.w3m/keymap -# -# # for x session -# keymap xs COMMAND "READ_SHELL ~/.w3m/cgi-bin/fzf_surfraw.cgi ; BACK ; GOTO /usr/lib/w3m/cgi-bin/goto_clipboard_primary.cgi ; REDRAW" -# keymap XS COMMAND "READ_SHELL ~/.w3m/cgi-bin/fzf_surfraw.cgi ; BACK ; TAB_GOTO /usr/lib/w3m/cgi-bin/goto_clipboard_primary.cgi ; REDRAW" -# # for tmux users -# # keymap xs COMMAND "READ_SHELL ~/.w3m/cgi-bin/fzf_surfraw.cgi ; BACK ; GOTO /usr/lib/w3m/cgi-bin/goto_tmux_clipboard.cgi ; REDRAW" -# # keymap XS COMMAND "READ_SHELL ~/.w3m/cgi-bin/fzf_surfraw.cgi ; BACK ; TAB_GOTO /usr/lib/w3m/cgi-bin/goto_tmux_clipboard.cgi ; REDRAW" - - -# CLOG: 2021-04-11 version 0.4 remove read command for posix compatible (good idea by https://github.com/NapoleonWils0n) -# new keymap use READ_SHELL and tmux load-buffer to avoid unnecessary prompt -# 2021-02-05 version 0.3 copy to all 3 clipboard at once; xsel primary/system clipboard, tmux clipboard -# 2020-05-08 version 0.2 surfraw -p instead of echo -# 2020-04-27 version 0.1 +# DEPEND: surfraw fzf gawk coreutils grep +# REQD: 1. chmod +x ~/.w3m/cgi-bin/fzf_surfraw.cgi +# 2. chmod +x ~/.w3m/cgi-bin/goto_w3m_clipboard.cgi +# 3. sed -i 's@cgi_bin.*@cgi_bin ~/.w3m/cgi-bin:/usr/lib/w3m/cgi-bin:/usr/local/libexec/w3m/cgi-bin@g' ~/.w3m/config +# 4. sed -i 's@default_url.*@default_url 1@g' ~/.w3m/config +# 5. $EDITOR ~/.w3m/keymap +# # search with surfraw (no clipboard required) +# keymap xs COMMAND "READ_SHELL ~/.w3m/cgi-bin/fzf_surfraw.cgi ; BACK ; GOTO file:/cgi-bin/goto_w3m_clipboard.cgi" +# keymap XS COMMAND "READ_SHELL ~/.w3m/cgi-bin/fzf_surfraw.cgi ; BACK ; TAB_GOTO file:/cgi-bin/goto_w3m_clipboard.cgi" + +# CLOG: 2021-05-23 detect if tmux is running then use fzf-tmux split pane +# 2021-05-22 fzf --tiebreak to sort, no longer require any clipboard use tmpfile instead +# 2021-04-11 remove read command for posix compatible (good idea by https://github.com/NapoleonWils0n) +# new keymap use READ_SHELL and tmux load-buffer to avoid unnecessary prompt +# 2021-02-05 copy to all 3 clipboard at once; xsel primary/system clipboard, tmux clipboard +# 2020-05-08 surfraw -p instead of echo +# 2020-04-27 starting point # clear screen printf "\033c" -# select your elvi -# PREFIX=$(surfraw -elvi | grep -v 'LOCAL\|GLOBAL'| fzf -e | awk '{print $1}') -PREFIX=$(surfraw -elvi | grep -v 'LOCAL\|GLOBAL' | fzf -e --prompt='Pick search engine: ' --info=inline --layout=reverse | awk '{print $1}') - -# exit script if no elvi is selected (e.g hit ESC) -# if [ "$PREFIX" = "" ]; then exit; fi -[ -z "$PREFIX" ] && exit - -# get user input -# read -r -e -p " $PREFIX >> Enter Your Search Keyword: " INPUT -INPUT=$(printf | fzf --print-query --prompt="Enter keyword(s) to search ${PREFIX}: " --info=inline --layout=reverse) - -# print proper url and copy to primary clipboard (aka highlighted clipboard) and tmux clipboard -# note: dont quote $INPUT it will mess up results -# ------------------------------- -# copy to xsel primary (aka shift-insert) -surfraw -p "$PREFIX" $INPUT | xsel -p - -# copy to xsel system clipboard (aka ctrl-v) -# surfraw -p "$PREFIX" $INPUT | xsel -b - -# copy to tmux clipboard -# tmux set-buffer "$(surfraw -p "$PREFIX" $INPUT)" -# pidof tmux >/dev/null && tmux set-buffer "$(surfraw -p "$PREFIX" "$INPUT")" -surfraw -p "$PREFIX" $INPUT | tmux load-buffer - - +# check if tmux is running on current window +if [ "$TERM_PROGRAM" = tmux ]; then + PREFIX=$(surfraw -elvi | grep -v 'LOCAL\|GLOBAL' | fzf-tmux -d 30% -e --prompt='Pick search engine: ' --info=inline --layout=reverse --tiebreak=index | awk '{print $1}') + [ -z "$PREFIX" ] && exit + INPUT=$(printf "\n" | fzf-tmux -d 30% --print-query --prompt="Enter keyword(s) to search ${PREFIX}: " --info=inline --layout=reverse) +else + PREFIX=$(surfraw -elvi | grep -v 'LOCAL\|GLOBAL' | fzf -e --prompt='Pick search engine: ' --info=inline --layout=reverse --tiebreak=index | awk '{print $1}') + [ -z "$PREFIX" ] && exit + INPUT=$(printf "\n" | fzf --print-query --prompt="Enter keyword(s) to search ${PREFIX}: " --info=inline --layout=reverse) +fi + +# NOTE: dont quote $INPUT it will mess up results +# surfraw -p "$PREFIX" $INPUT | xsel -p # xsel primary (aka shift-insert or middle click to paste) +# surfraw -p "$PREFIX" $INPUT | xsel -b # xsel system (aka ctrl-v to paste) +# surfraw -p "$PREFIX" $INPUT | tmux load-buffer - +surfraw -p "$PREFIX" $INPUT > /tmp/w3m_clipboard.txt # w3m clipboard using tmpfile diff --git a/w3m_plugins/cgi-bin/goto_clipboard.cgi b/w3m_plugins/cgi-bin/goto_clipboard.cgi new file mode 100755 index 0000000..2459d02 --- /dev/null +++ b/w3m_plugins/cgi-bin/goto_clipboard.cgi @@ -0,0 +1,30 @@ +#!/usr/bin/env sh +# AUTHOR: gotbletu (@gmail|twitter|youtube|github|lbry) +# https://www.youtube.com/user/gotbletu +# DESC: paste and go feature for w3m web browser using system clipboard (aka ctrl+v) +# DEMO: https://youtu.be/p5NZb8f8AHA | updated https://youtu.be/0j3pUfZjCeQ +# REQD: 1. chmod +x ~/.w3m/cgi-bin/goto_clipboard.cgi +# 2. sed -i 's@cgi_bin.*@cgi_bin ~/.w3m/cgi-bin:/usr/lib/w3m/cgi-bin:/usr/local/libexec/w3m/cgi-bin@g' ~/.w3m/config +# 3. sed -i 's@default_url.*@default_url 1@g' ~/.w3m/config +# 4. $EDITOR ~/.w3m/keymap +# keymap pp GOTO file:/cgi-bin/goto_clipboard.cgi +# keymap PP TAB_GOTO file:/cgi-bin/goto_clipboard.cgi + +# REFF: https://github.com/felipesaa/A-vim-like-firefox-like-configuration-for-w3m +# CLOG: 2021-05-22 version 0.3 new instructions, no longer required root path for cgi scripts +# 2021-02-05 version 0.2 reset url back to 1 (aka edit current url) +# 2020-04-26 version 0.1 + +# set open-url value to zero (aka empty url line) +printf "%s\r\n" "W3m-control: SET_OPTION default_url=0" + +#GOTO url in clipboard in current page. If the clipboard has a +#"non url string/nothing" an blank page is shown. +printf "%s\r\n" "W3m-control: GOTO $(xsel -ob)" + +#delete the buffer (element in history) created between the current page and +#the searched page by calling this script. +printf "%s\r\n" "W3m-control: DELETE_PREVBUF" + +# set default open-url value to one (aka current url) +printf "%s\r\n" "W3m-control: SET_OPTION default_url=1" diff --git a/w3m_plugins/cgi-bin/goto_clipboard_primary.cgi b/w3m_plugins/cgi-bin/goto_clipboard_primary.cgi new file mode 100755 index 0000000..873b94e --- /dev/null +++ b/w3m_plugins/cgi-bin/goto_clipboard_primary.cgi @@ -0,0 +1,29 @@ +#!/usr/bin/env sh +# AUTHOR: gotbletu (@gmail|twitter|youtube|github|lbry) +# https://www.youtube.com/user/gotbletu +# DESC: paste and go feature for w3m web browser using primary clipboard (aka shift+insert) +# DEMO: https://youtu.be/p5NZb8f8AHA | updated https://youtu.be/0j3pUfZjCeQ +# REQD: 1. chmod +x ~/.w3m/cgi-bin/goto_clipboard_primary.cgi +# 2. sed -i 's@cgi_bin.*@cgi_bin ~/.w3m/cgi-bin:/usr/lib/w3m/cgi-bin:/usr/local/libexec/w3m/cgi-bin@g' ~/.w3m/config +# 3. sed -i 's@default_url.*@default_url 1@g' ~/.w3m/config +# 4. $EDITOR ~/.w3m/keymap +# keymap pp GOTO file:/cgi-bin/goto_clipboard_primary.cgi +# keymap PP TAB_GOTO file:/cgi-bin/goto_clipboard_primary.cgi + +# CLOG: 2021-05-22 version 0.3 new instructions, no longer required root path for cgi scripts +# 2021-02-05 version 0.2 reset url back to 1 (aka edit current url) +# 2020-04-26 version 0.1 + +# set open-url value to zero (aka empty url line) +printf "%s\r\n" "W3m-control: SET_OPTION default_url=0" + +#GOTO url in clipboard in current page. If the clipboard has a +#"non url string/nothing" an blank page is shown. +printf "%s\r\n" "W3m-control: GOTO $(xsel -op)" + +#delete the buffer (element in history) created between the current page and +#the searched page by calling this script. +printf "%s\r\n" "W3m-control: DELETE_PREVBUF" + +# set default open-url value to one (aka current url) +printf "%s\r\n" "W3m-control: SET_OPTION default_url=1" diff --git a/w3m_plugins/cgi-bin/goto_tmux_clipboard.cgi b/w3m_plugins/cgi-bin/goto_tmux_clipboard.cgi new file mode 100755 index 0000000..85db2cb --- /dev/null +++ b/w3m_plugins/cgi-bin/goto_tmux_clipboard.cgi @@ -0,0 +1,29 @@ +#!/usr/bin/env sh +# AUTHOR: gotbletu (@gmail|twitter|youtube|github|lbry) +# https://www.youtube.com/user/gotbletu +# DESC: paste and go feature for w3m web browser using tmux clipboard +# DEMO: https://youtu.be/p5NZb8f8AHA | updated https://youtu.be/0j3pUfZjCeQ +# REQD: 1. chmod +x ~/.w3m/cgi-bin/goto_tmux_clipboard.cgi +# 2. sed -i 's@cgi_bin.*@cgi_bin ~/.w3m/cgi-bin:/usr/lib/w3m/cgi-bin:/usr/local/libexec/w3m/cgi-bin@g' ~/.w3m/config +# 3. sed -i 's@default_url.*@default_url 1@g' ~/.w3m/config +# 4. $EDITOR ~/.w3m/keymap +# keymap pt GOTO file:/cgi-bin/goto_tmux_clipboard.cgi +# keymap PT TAB_GOTO file:/cgi-bin/goto_tmux_clipboard.cgi +# +# CLOG: 2021-05-22 version 0.3 new instructions, no longer required root path for cgi scripts +# 2021-02-05 version 0.2 reset url back to 1 (aka edit current url) +# 2020-04-26 version 0.1 + +# set open-url value to zero (aka empty url line) +printf "%s\r\n" "W3m-control: SET_OPTION default_url=0" + +#GOTO url in clipboard in current page. If the clipboard has a +#"non url string/nothing" an blank page is shown. +printf "%s\r\n" "W3m-control: GOTO $(tmux paste-buffer)" + +#delete the buffer (element in history) created between the current page and +#the searched page by calling this script. +printf "%s\r\n" "W3m-control: DELETE_PREVBUF" + +# set default open-url value to one (aka current url) +printf "%s\r\n" "W3m-control: SET_OPTION default_url=1" diff --git a/w3m_plugins/cgi-bin/goto_w3m_clipboard.cgi b/w3m_plugins/cgi-bin/goto_w3m_clipboard.cgi new file mode 100755 index 0000000..d22fd9d --- /dev/null +++ b/w3m_plugins/cgi-bin/goto_w3m_clipboard.cgi @@ -0,0 +1,27 @@ +#!/usr/bin/env sh +# AUTHOR: gotbletu (@gmail|twitter|youtube|github|lbry) +# https://www.youtube.com/user/gotbletu +# DESC: paste and go feature for w3m web browser +# DEMO: https://youtu.be/p5NZb8f8AHA | updated https://youtu.be/0j3pUfZjCeQ +# REQD: 1. chmod +x ~/.w3m/cgi-bin/goto_w3m_clipboard.cgi +# 2. sed -i 's@cgi_bin.*@cgi_bin ~/.w3m/cgi-bin:/usr/lib/w3m/cgi-bin:/usr/local/libexec/w3m/cgi-bin@g' ~/.w3m/config +# 3. sed -i 's@default_url.*@default_url 1@g' ~/.w3m/config +# 4. $EDITOR ~/.w3m/keymap +# keymap pw GOTO file:/cgi-bin/goto_w3m_clipboard.cgi +# keymap PW TAB_GOTO file:/cgi-bin/goto_w3m_clipboard.cgi +# +# CLOG: 2021-05-22 0.1 + +# set open-url value to zero (aka empty url line) +printf "%s\r\n" "W3m-control: SET_OPTION default_url=0" + +#GOTO url in clipboard in current page. If the clipboard has a +#"non url string/nothing" an blank page is shown. +printf "%s\r\n" "W3m-control: GOTO $(cat /tmp/w3m_clipboard.txt)" + +#delete the buffer (element in history) created between the current page and +#the searched page by calling this script. +printf "%s\r\n" "W3m-control: DELETE_PREVBUF" + +# set default open-url value to one (aka current url) +printf "%s\r\n" "W3m-control: SET_OPTION default_url=1" diff --git a/w3m_plugins/cgi-bin/magnet.cgi b/w3m_plugins/cgi-bin/magnet.cgi index 835c96b..7bff061 100755 --- a/w3m_plugins/cgi-bin/magnet.cgi +++ b/w3m_plugins/cgi-bin/magnet.cgi @@ -3,11 +3,16 @@ # https://www.youtube.com/user/gotbletu # DESC: send magnet links to your torrent client (for W3M Web Browser) # DEMO: https://youtu.be/T74FqHMHjN0 +# REFF: decodingurl https://sodocumentation.net/bash/topic/10895/decoding-url # REQD: 1. touch ~/.w3m/urimethodmap # 2. echo "magnet: file:/cgi-bin/magnet.cgi?%s" >> ~/.w3m/urimethodmap # 3. chmod +x ~/.w3m/cgi-bin/magnet.cgi # 4. sed -i 's@cgi_bin.*@cgi_bin ~/.w3m/cgi-bin:/usr/lib/w3m/cgi-bin:/usr/local/libexec/w3m/cgi-bin@g' ~/.w3m/config # 5. sed -i 's@urimethodmap.*@urimethodmap ~/.w3m/urimethodmap, /usr/etc/w3m/urimethodmap@g' ~/.w3m/config +# CLOG: 2021-05-22 0.2 decode any encoded url (e.g gopherbay on floodgap web proxy) +# 2021-05-15 0.1 all w3m-control + +QUERY_STRING="$(printf "%s" "$QUERY_STRING" | sed -e "s/%\([0-9A-F][0-9A-F]\)/\\\\\x\1/g" | xargs -0 echo -e)" transmission-remote --add "$QUERY_STRING" printf "%s\r\n" "W3m-control: BACK" diff --git a/w3m_plugins/cgi-bin/redirect_duckduckgo.cgi b/w3m_plugins/cgi-bin/redirect_duckduckgo.cgi new file mode 100755 index 0000000..c21741a --- /dev/null +++ b/w3m_plugins/cgi-bin/redirect_duckduckgo.cgi @@ -0,0 +1,16 @@ +#!/usr/bin/env sh +# AUTHOR: gotbletu (@gmail|twitter|youtube|github|lbry) +# https://www.youtube.com/user/gotbletu +# DESC: remove all duckduckgo redirect links +# DEMO: https://youtu.be/rM5vBRfwwzc +# REFF: grep string between two words https://stackoverflow.com/a/13245961 +# REQD: 1. $EDITOR ~/.w3m/siteconf +# url m@^https?://duckduckgo.com/l/\?uddg@ +# substitute_url "file:///cgi-bin/redirect_duckduckgo.cgi?" +# 2. chmod +x ~/.w3m/cgi-bin/redirect_duckduckgo.cgi +# 3. sed -i 's@cgi_bin.*@cgi_bin ~/.w3m/cgi-bin:/usr/lib/w3m/cgi-bin:/usr/local/libexec/w3m/cgi-bin@g' ~/.w3m/config + +W3M_CURRENT_LINK="$(printf "%s" "$W3M_CURRENT_LINK" | grep -oP '(?<=duckduckgo.com\/l\/\?uddg=).*(?=&)' | sed -e "s/%\([0-9A-F][0-9A-F]\)/\\\\\x\1/g" | xargs -0 echo -e)" +printf "%s\r\n" "W3m-control: GOTO $W3M_CURRENT_LINK" +printf "%s\r\n" "W3m-control: DELETE_PREVBUF" + diff --git a/w3m_plugins/cgi-bin/redirect_google.cgi b/w3m_plugins/cgi-bin/redirect_google.cgi new file mode 100755 index 0000000..923d9a6 --- /dev/null +++ b/w3m_plugins/cgi-bin/redirect_google.cgi @@ -0,0 +1,14 @@ +#!/usr/bin/env sh +# AUTHOR: gotbletu (@gmail|twitter|youtube|github|lbry) +# https://www.youtube.com/user/gotbletu +# DESC: remove all google redirect links +# DEMO: https://youtu.be/rM5vBRfwwzc +# REQD: 1. $EDITOR ~/.w3m/siteconf +# url m@^https?://(.*\.)google.com/url@ +# substitute_url "file:///cgi-bin/redirect_google.cgi?" +# 2. chmod +x ~/.w3m/cgi-bin/redirect_google.cgi +# 3. sed -i 's@cgi_bin.*@cgi_bin ~/.w3m/cgi-bin:/usr/lib/w3m/cgi-bin:/usr/local/libexec/w3m/cgi-bin@g' ~/.w3m/config + +W3M_CURRENT_LINK="$(printf "%s" "$W3M_CURRENT_LINK" | grep -oP '(?<=google.com\/url\?q=)[^&]*(?=&)' | sed -e "s/%\([0-9A-F][0-9A-F]\)/\\\\\x\1/g" | xargs -0 echo -e)" +printf "%s\r\n" "W3m-control: GOTO $W3M_CURRENT_LINK" +printf "%s\r\n" "W3m-control: DELETE_PREVBUF" diff --git a/w3m_plugins/cgi-bin/gopher_redirect.cgi b/w3m_plugins/cgi-bin/redirect_gopher.cgi similarity index 80% rename from w3m_plugins/cgi-bin/gopher_redirect.cgi rename to w3m_plugins/cgi-bin/redirect_gopher.cgi index 1e7282a..1bfc1f0 100755 --- a/w3m_plugins/cgi-bin/gopher_redirect.cgi +++ b/w3m_plugins/cgi-bin/redirect_gopher.cgi @@ -5,8 +5,8 @@ # DEMO: https://youtu.be/rM5vBRfwwzc # REQD: 1. $EDITOR ~/.w3m/siteconf # url m@^gopher?://(.*)hURL:@ -# substitute_url "file:///cgi-bin/gopher_redirect.cgi?" -# 2. chmod +x ~/.w3m/cgi-bin/gopher_redirect.cgi +# substitute_url "file:///cgi-bin/redirect_gopher.cgi?" +# 2. chmod +x ~/.w3m/cgi-bin/redirect_gopher.cgi # 3. sed -i 's@cgi_bin.*@cgi_bin ~/.w3m/cgi-bin:/usr/lib/w3m/cgi-bin:/usr/local/libexec/w3m/cgi-bin@g' ~/.w3m/config # Note: check if you have native gopher protocol support @@ -15,6 +15,6 @@ # remove gopher hURL header link # e.g gopher://gopher.floodgap.com/hURL:http://www.floodgap.com/ --> http://www.floodgap.com/ -QUERY_STRING=$(printf "%s\n" "$QUERY_STRING" | sed 's@^gopher.*hURL:@@') +QUERY_STRING=$(printf "%s" "$QUERY_STRING" | sed 's@^gopher.*hURL:@@') printf "%s\r\n" "W3m-control: GOTO $QUERY_STRING" printf "%s\r\n" "W3m-control: DELETE_PREVBUF" diff --git a/w3m_plugins/cgi-bin/restore_session.cgi b/w3m_plugins/cgi-bin/restore_session.cgi index 8453bbf..8b840fb 100755 --- a/w3m_plugins/cgi-bin/restore_session.cgi +++ b/w3m_plugins/cgi-bin/restore_session.cgi @@ -4,11 +4,10 @@ # 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 sed -# 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 -# +# REQD: 1. chmod +x ~/.w3m/cgi-bin/restore_session.cgi +# 2. $EDITOR ~/.bashrc +# [ -d "$HOME/.w3m/bin" ] && PATH="$HOME/.w3m/bin:$PATH" +# 3. $EDITOR ~/.w3m/keymap # ############################ Quit with confirmation request (QUIT) # keymap :q QUIT # keymap ZZ QUIT @@ -16,13 +15,12 @@ # 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 +# CLOG: 2021-05-15 remove multiple -N flag +# 2021-04-17 first draft, no option to jump to tab 1 at the moment + ## --------------------------------------------- # location of generated script of last session mkdir -p "$HOME/.w3m/bin" @@ -30,27 +28,24 @@ RESTORE_SESSSION="$HOME/.w3m/bin/w3mlastsession" # add shell header echo "#!/usr/bin/env sh" > "$RESTORE_SESSSION" -echo "w3m \\" >> "$RESTORE_SESSSION" +echo "w3m -N \\" >> "$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 +# remove dupes without sorting and append trailing slash to each url +awk '!x[$0]++' "$HOME/.w3m/RestoreSession.txt" | while read -r line ; do echo "'$line' \\" >> "$RESTORE_SESSSION" ; done # remove last trailing slash of the last line sed -i '$ s-.$--' "$RESTORE_SESSSION" -# note: dont use /dev/null it prevents fzf_surfraw.cgi -# 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' +## w3m -N \ +## 'https://www.reddit.com/r/w3m/.mobile' \ +## 'https://www.reddit.com/r/commandline/.mobile' \ +## 'https://www.reddit.com/r/linux/.mobile' \ +## 'http://lite.cnn.com/en' \ +## 'https://raw.githubusercontent.com/tats/w3m/master/ChangeLog' \ +## 'https://github.com/gotbletu/shownotes' ## -------------------------------------------------- diff --git a/w3m_plugins/root-cgi-bin/restore_tab.cgi b/w3m_plugins/cgi-bin/restore_tab.cgi similarity index 61% rename from w3m_plugins/root-cgi-bin/restore_tab.cgi rename to w3m_plugins/cgi-bin/restore_tab.cgi index 298ab3d..9fa23de 100755 --- a/w3m_plugins/root-cgi-bin/restore_tab.cgi +++ b/w3m_plugins/cgi-bin/restore_tab.cgi @@ -2,13 +2,11 @@ # AUTHOR: felipesaa (https://github.com/felipesaa) # DESC: restore a closed tab in w3m # DEMO: https://youtu.be/e5_q3-r6PAU -# DEPEND: coreutils -# REFF: https://github.com/felipesaa/A-vim-like-firefox-like-configuration-for-w3m -# http://w3m.sourceforge.net/MANUAL#LocalCGI -# RQMTS: 1. allow executable permissions and put this script in /usr/lib/w3m/cgi-bin/ -# 2. vim ~/.w3m/keymap +# RQMTS: 1. chmod +x ~/.w3m/cgi-bin/restore_tab.cgi +# 2. sed -i 's@cgi_bin.*@cgi_bin ~/.w3m/cgi-bin:/usr/lib/w3m/cgi-bin:/usr/local/libexec/w3m/cgi-bin@g' ~/.w3m/config +# 3. $EDITOR ~/.w3m/keymap # keymap d COMMAND "EXTERN 'echo %s >> ~/.w3m/RestoreTab.txt' ; CLOSE_TAB" -# keymap u TAB_GOTO /usr/lib/w3m/cgi-bin/restore_tab.cgi +# keymap u TAB_GOTO file:/cgi-bin/restore_tab.cgi #Open the last closed tab last_tab=$(tail -n 1 ~/.w3m/RestoreTab.txt); diff --git a/w3m_plugins/root-cgi-bin/goto_clipboard.cgi b/w3m_plugins/root-cgi-bin/goto_clipboard.cgi deleted file mode 100755 index 2fb00f6..0000000 --- a/w3m_plugins/root-cgi-bin/goto_clipboard.cgi +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env sh -# AUTHOR: gotbletu (@gmail|twitter|youtube|github|lbry) -# https://www.youtube.com/user/gotbletu -# DESC: paste and go feature for w3m web browser using system clipboard (aka ctrl+v) -# DEMO: https://youtu.be/p5NZb8f8AHA | updated https://youtu.be/0j3pUfZjCeQ -# DEPEND: w3m xsel -# RQMTS: 1. allow permissions and put this script in /usr/lib/w3m/cgi-bin/ -# -# 2. $EDITOR ~/.w3m/keymap -# # paste url and go (current tab) -# keymap pp GOTO /usr/lib/w3m/cgi-bin/goto_clipboard.cgi -# -# # paste url and go (new tab) -# keymap PP TAB_GOTO /usr/lib/w3m/cgi-bin/goto_clipboard.cgi -# -# 3. set the default open-url to current url -# sed -i 's:default_url.*:default_url 1:g' ~/.w3m/config -# -# REFF: https://github.com/felipesaa/A-vim-like-firefox-like-configuration-for-w3m -# CLOG: 2021-02-05 version 0.2 reset url back to 1 (aka edit current url) -# 2018-09-30 version 0.1 by felipesaa (https://github.com/felipesaa) - - -# set open-url value to zero (aka empty url line) -printf "%s\r\n" "W3m-control: SET_OPTION default_url=0"; - -#GOTO url in clipboard in current page. If the clipboard has a -#"non url string/nothing" an blank page is shown. -printf "%s\r\n" "W3m-control: GOTO $(xsel -ob)"; - -#delete the buffer (element in history) created between the current page and -#the searched page by calling this script. -printf "W3m-control: DELETE_PREVBUF\r\n" - -# set default open-url value to one (aka current url) -printf "%s\r\n" "W3m-control: SET_OPTION default_url=1"; - diff --git a/w3m_plugins/root-cgi-bin/goto_clipboard_primary.cgi b/w3m_plugins/root-cgi-bin/goto_clipboard_primary.cgi deleted file mode 100755 index 91306bf..0000000 --- a/w3m_plugins/root-cgi-bin/goto_clipboard_primary.cgi +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env sh -# AUTHOR: gotbletu (@gmail|twitter|youtube|github|lbry) -# https://www.youtube.com/user/gotbletu -# DESC: paste and go feature for w3m web browser using primary clipboard (aka shift+insert) -# DEMO: https://youtu.be/p5NZb8f8AHA | updated https://youtu.be/0j3pUfZjCeQ -# DEPEND: w3m xsel -# RQMTS: 1. allow permissions and put this script in /usr/lib/w3m/cgi-bin/ -# -# 2. $EDITOR ~/.w3m/keymap -# # paste url and go (current tab) -# keymap pp GOTO /usr/lib/w3m/cgi-bin/goto_clipboard_primary.cgi -# -# # paste url and go (new tab) -# keymap PP TAB_GOTO /usr/lib/w3m/cgi-bin/goto_clipboard_primary.cgi -# -# 3. set the default open-url to current url -# sed -i 's:default_url.*:default_url 1:g' ~/.w3m/config -# -# REFF: https://github.com/felipesaa/A-vim-like-firefox-like-configuration-for-w3m -# CLOG: 2021-02-05 version 0.2 reset url back to 1 (aka edit current url) -# 2020-04-26 version 0.1 - - -# set open-url value to zero (aka empty url line) -printf "%s\r\n" "W3m-control: SET_OPTION default_url=0"; - -#GOTO url in clipboard in current page. If the clipboard has a -#"non url string/nothing" an blank page is shown. -printf "%s\r\n" "W3m-control: GOTO $(xsel -op)"; - -#delete the buffer (element in history) created between the current page and -#the searched page by calling this script. -printf "W3m-control: DELETE_PREVBUF\r\n" - -# set default open-url value to one (aka current url) -printf "%s\r\n" "W3m-control: SET_OPTION default_url=1"; - diff --git a/w3m_plugins/root-cgi-bin/goto_tmux_clipboard.cgi b/w3m_plugins/root-cgi-bin/goto_tmux_clipboard.cgi deleted file mode 100755 index 585b975..0000000 --- a/w3m_plugins/root-cgi-bin/goto_tmux_clipboard.cgi +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env sh -# AUTHOR: gotbletu (@gmail|twitter|youtube|github|lbry) -# https://www.youtube.com/user/gotbletu -# DESC: paste and go feature for w3m web browser using tmux clipboard -# DEMO: https://youtu.be/p5NZb8f8AHA | updated https://youtu.be/0j3pUfZjCeQ -# DEPEND: w3m tmux -# RQMTS: 1. allow permissions and put this script in /usr/lib/w3m/cgi-bin/ -# -# 2. $EDITOR ~/.w3m/keymap -# # paste url and go (current tab) -# keymap pp GOTO /usr/lib/w3m/cgi-bin/goto_tmux_clipboard.cgi -# -# # paste url and go (new tab) -# keymap PP TAB_GOTO /usr/lib/w3m/cgi-bin/goto_tmux_clipboard.cgi -# -# 3. set the default open-url to current url -# sed -i 's:default_url.*:default_url 1:g' ~/.w3m/config -# -# REFF: https://github.com/felipesaa/A-vim-like-firefox-like-configuration-for-w3m -# CLOG: 2021-02-05 version 0.2 reset url back to 1 (aka edit current url) -# 2020-04-26 version 0.1 - - -# set open-url value to zero (aka empty url line) -printf "%s\r\n" "W3m-control: SET_OPTION default_url=0"; - -#GOTO url in clipboard in current page. If the clipboard has a -#"non url string/nothing" an blank page is shown. -printf "%s\r\n" "W3m-control: GOTO $(tmux paste-buffer)"; - -#delete the buffer (element in history) created between the current page and -#the searched page by calling this script. -printf "W3m-control: DELETE_PREVBUF\r\n" - -# set default open-url value to one (aka current url) -printf "%s\r\n" "W3m-control: SET_OPTION default_url=1"; - diff --git a/w3m_prefix_search.md b/w3m_prefix_search.md index 220a79c..ef3d95b 100644 --- a/w3m_prefix_search.md +++ b/w3m_prefix_search.md @@ -7,43 +7,43 @@ improving w3m by having a quick way to search multiple search engines or even cu tags: linux w3m omnibar address bar quick w3m smart search fzf fuzzy finder surfraw tmux workaround current url ### install requirements - w3m surfraw fzf gawk coreutils grep (xsel or tmux) - -### install scripts to root directory -Download at [root-cgi-bin](w3m_plugins/root-cgi-bin) - ----- - # save it to - - /usr/lib/w3m/cgi-bin/goto_clipboard_primary.cgi - /usr/lib/w3m/cgi-bin/goto_clipboard.cgi - /usr/lib/w3m/cgi-bin/goto_tmux_clipboard.cgi ----- - chmod +x + w3m surfraw fzf gawk coreutils grep ### install script to local directory -Download at [cgi-bin](w3m_plugins/cgi-bin) +[Download at cgi-bin](w3m_plugins/cgi-bin) ---- - # save it to ~/.w3m/cgi-bin/fzf_surfraw.cgi + ~/.w3m/cgi-bin/goto_clipboard.cgi + ~/.w3m/cgi-bin/goto_clipboard_primary.cgi + ~/.w3m/cgi-bin/goto_tmux_clipboard.cgi + ~/.w3m/cgi-bin/goto_w3m_clipboard.cgi + ---- - chmod +x + chmod +x ~/.w3m/cgi-bin/*.cgi ### configuration vim ~/.w3m/keymap - # for x sessions - keymap xs COMMAND "READ_SHELL ~/.w3m/cgi-bin/fzf_surfraw.cgi ; BACK ; GOTO /usr/lib/w3m/cgi-bin/goto_clipboard_primary.cgi ; REDRAW" - keymap XS COMMAND "READ_SHELL ~/.w3m/cgi-bin/fzf_surfraw.cgi ; BACK ; TAB_GOTO /usr/lib/w3m/cgi-bin/goto_clipboard_primary.cgi ; REDRAW" + # search with surfraw (no clipboard required) + keymap xs COMMAND "READ_SHELL ~/.w3m/cgi-bin/fzf_surfraw.cgi ; BACK ; GOTO file:/cgi-bin/goto_w3m_clipboard.cgi" + keymap XS COMMAND "READ_SHELL ~/.w3m/cgi-bin/fzf_surfraw.cgi ; BACK ; TAB_GOTO file:/cgi-bin/goto_w3m_clipboard.cgi" - # for tmux users - # keymap xs COMMAND "READ_SHELL ~/.w3m/cgi-bin/fzf_surfraw.cgi ; BACK ; GOTO /usr/lib/w3m/cgi-bin/goto_tmux_clipboard.cgi ; REDRAW" - # keymap XS COMMAND "READ_SHELL ~/.w3m/cgi-bin/fzf_surfraw.cgi; BACK ; TAB_GOTO /usr/lib/w3m/cgi-bin/goto_tmux_clipboard.cgi ; REDRAW" + # yank url to multiple clipboard + keymap yy EXTERN_LINK "url=%s ; echo "$url" > /tmp/w3m_clipboard.txt ; echo "$url" | xsel -b ; echo "$url" | tmux load-buffer -" + keymap YY EXTERN "url=%s ; echo "$url" > /tmp/w3m_clipboard.txt ; echo "$url" | xsel -b ; echo "$url" | tmux load-buffer -" + # paste url and go + keymap pp GOTO file:/cgi-bin/goto_clipboard.cgi + keymap PP TAB_GOTO file:/cgi-bin/goto_clipboard.cgi + keymap pt GOTO file:/cgi-bin/goto_tmux_clipboard.cgi + keymap PT TAB_GOTO file:/cgi-bin/goto_tmux_clipboard.cgi + keymap pw GOTO file:/cgi-bin/goto_w3m_clipboard.cgi + keymap PW TAB_GOTO file:/cgi-bin/goto_w3m_clipboard.cgi -### set the default open-url to current url +### change config settings + sed -i 's@cgi_bin.*@cgi_bin ~/.w3m/cgi-bin:/usr/lib/w3m/cgi-bin:/usr/local/libexec/w3m/cgi-bin@g' ~/.w3m/config sed -i 's:default_url.*:default_url 1:g' ~/.w3m/config ### usage example