summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordefanor <defanor@uberspace.net>2017-12-06 10:18:54 +0300
committerdefanor <defanor@uberspace.net>2017-12-06 10:18:54 +0300
commitd09155bcb8ce047d33ce97c34ae0c972281fe99d (patch)
tree0f825bdda1a975cfc81930294cc302f1ab1924d2
parentb075319adfe2b12fe81c5a4f8c5257e99e649a54 (diff)
Add a web.archive.org shortcut into the default configuration
Finding the last HTTP 200 response via the availability API, so a dummy "web-archive" scheme is added into the default configuration in order to use a custom command. The URI_ESCAPED environment variable is also introduced, though not used here -- but may be handy for similar custom commands.
-rw-r--r--Pancake/Configuration.hs16
-rw-r--r--Pancake/Reading.hs4
-rw-r--r--README8
3 files changed, 20 insertions, 8 deletions
diff --git a/Pancake/Configuration.hs b/Pancake/Configuration.hs
index 7c537bc..9ad60dc 100644
--- a/Pancake/Configuration.hs
+++ b/Pancake/Configuration.hs
@@ -82,9 +82,12 @@ instance Default Config where
[ ("ssh", "scp \"${URI_REGNAME}:${URI_PATH}\" /dev/stdout"
++ " && echo -e '\n-pancake-'")
, ("gopher", "curl \"${URI}\""
- ++ " -w \"\n-pancake-\n\"")]
- , defaultCommand = "curl --compressed -4 -L \"${URI}\""
- ++ " -w \"\n-pancake-\nuri: %{url_effective}\ntype: %{content_type}\n\""
+ ++ " -w \"\n-pancake-\n\"")
+ , ("web-archive", concat
+ [ curl
+ , "\"$(curl \"https://archive.org/wayback/available${URI_QUERY}"
+ , "\" | jq -r '.archived_snapshots.closest.url')\"" ])]
+ , defaultCommand = curl ++ "\"${URI}\""
, externalViewers = M.fromList $
map (flip (,) "emacsclient -n \"${FILE}\"")
["hs", "cabal", "c", "h", "el", "scm", "idr"]
@@ -98,12 +101,17 @@ instance Default Config where
, ("g", "https://m.gutenberg.org/ebooks/search.mobile/?query=")
, ("xiph", "http://dir.xiph.org/search?search=")
, ("gp", "gopher://gopherpedia.com:70/7/lookup?")
- , ("vs", "gopher://gopher.floodgap.com/7/v2/vs?")]
+ , ("vs", "gopher://gopher.floodgap.com/7/v2/vs?")
+ , ("wa", "web-archive:///?url=")]
, paginate = True
, historyDepth = 100
, referenceDigits = "0123456789"
, indentDivs = False
}
+ where
+ curl = concat
+ [ "curl --compressed -4 -L "
+ , "-w \"\n-pancake-\nuri: %{url_effective}\ntype: %{content_type}\n\" "]
-- | Loads configuration from an XDG config directory.
loadConfig :: MonadIO m => m Config
diff --git a/Pancake/Reading.hs b/Pancake/Reading.hs
index 0aa27f3..cdb4093 100644
--- a/Pancake/Reading.hs
+++ b/Pancake/Reading.hs
@@ -93,7 +93,9 @@ retrieve cmd uri = do
, ("URI_REGNAME", uriRegName x)
, ("URI_PORT", uriPort x) ])
(uriAuthority uri)
- environment = ("URI", uriToString id uri "")
+ uriStr = uriToString id uri ""
+ environment = ("URI", uriStr)
+ : ("URI_ESCAPED", escapeURIString isUnreserved uriStr)
: ("URI_SCHEME", uriScheme uri)
: ("URI_PATH", uriPath uri)
: ("URI_QUERY", uriQuery uri)
diff --git a/README b/README
index 5a1ea8f..c5a13db 100644
--- a/README
+++ b/README
@@ -82,7 +82,8 @@ Configuration
-------------
Default configuration will be written into XDG configuration
-directory, and would look approximately like this::
+directory, and would look approximately like this (slightly
+simplified)::
externalViewers:
png: xdg-open "${FILE}"
@@ -91,7 +92,7 @@ directory, and would look approximately like this::
commands:
gopher: torify curl "${URI}"
ssh: scp "${URI_REGNAME}:${URI_PATH}" /dev/stdout
- defaultCommand: ! 'curl --compressed -4 -L "${URI}" -w "
+ defaultCommand: ! 'curl --compressed -4 -L -w "
-pancake-
@@ -99,12 +100,13 @@ directory, and would look approximately like this::
type: %{content_type}
- "'
+ " "${URI}"'
referenceDigits: 'rstwfpxcvaqzdgb'
shortcuts:
g: https://m.gutenberg.org/ebooks/search.mobile/?query=
ddg: https://duckduckgo.com/lite/?q=
wt: https://en.m.wiktionary.org/w/index.php?search=
+ wa: web-archive:///?url=
wp: https://en.m.wikipedia.org/wiki/Special:Search?search=
gp: gopher://gopherpedia.com:70/7/lookup?
vs: gopher://gopher.floodgap.com/7/v2/vs?