summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Palfrader <peter@palfrader.org>2019-09-08 22:08:50 +0200
committerPeter Palfrader <peter@palfrader.org>2019-09-08 22:08:50 +0200
commitf1b4f350c7971b7b661fb77915a8bb6eb2c71598 (patch)
treef3c9bb5cb59f8a23ae687fa438a85304f75b0c20
parentad1d921617bd0319230269d32b1a8217b6402214 (diff)
Merge features from anarcat
- if stdin is text, publish the content as stdin.txt by default - new option -l to show last used token from history - new option -L to pass to rsync (--copy-links) - the screenshot tool (import) is now overridable in the config (set the screenshot variable)
-rwxr-xr-xpublish34
1 files changed, 32 insertions, 2 deletions
diff --git a/publish b/publish
index ff4c42a..af3eb0e 100755
--- a/publish
+++ b/publish
@@ -63,6 +63,9 @@ else
clipper=true
fi
+# the screenshot tool, expected take a screenshot of whatever and
+# write the image in the argument provided
+screenshot=import
rsync_pre_invoke() { true ;}
rsync_post_invoke() { true ;}
@@ -82,6 +85,7 @@ OPTIONS:
-8 Add a AddDefaultCharset UTF-8 .htaccess file.
-c CF Use config file CF.
-H Show the history.
+ -l Show last used token.
-s FN When reading data from stdin, use FN as filename to be published.
-S Make a screenshot of one window and publish.
-h Show this message.
@@ -94,6 +98,7 @@ OPTIONS:
-T tag directory name on the server (use this to re-publish under that name)
-x Publish the contents of the xclipboard.
-u Unpublish directory (only useful together with -T)
+ -L Follow symlinks
EOF
}
@@ -114,6 +119,16 @@ history_append() {
mv "$history_tmp" "$history_file"
}
+history_last() {
+ if [ -r "$history_file" ]; then
+ tail -1 "$history_file" | cut -d' ' -f3
+ return 0
+ else
+ echo "history file: '$history_file' not found"
+ return 3
+ fi
+}
+
history_show() {
cat "$history_file"
}
@@ -139,7 +154,7 @@ relative=""
d_server=""
unpublish=0
-while getopts "rRhnq8HSxc:s:t:T:u" OPTION
+while getopts "rRhnq8HSxc:s:t:T:uL" OPTION
do
case $OPTION in
h)
@@ -167,6 +182,10 @@ do
exit 3
fi
;;
+ l)
+ history_last
+ exit $?
+ ;;
S)
do_screenshot=1
;;
@@ -196,6 +215,9 @@ do
u)
unpublish=1
;;
+ L)
+ rsync_args="$rsync_args -L"
+ ;;
*)
usage >&2
exit 1
@@ -221,12 +243,16 @@ fi
if [[ "$do_screenshot" -gt 0 ]]; then
setup_tmpdir
img="$tmpdir/screenshot.png"
- import "$img"
+ $screenshot "$img"
chmod a+r "$img"
set dummy "$img" "$@"
shift
fi
+is_text() {
+ file -b -i "$1" | grep -q ^text
+}
+
if [[ "$#" = 0 ]]; then
setup_tmpdir
if [ "${name_stdin%-}" != "" ]; then
@@ -255,6 +281,10 @@ if [[ "$#" = 0 ]]; then
exit 1
fi
fi
+ if [ "${name_stdin%-}" == "" ] && is_text "$stdin" ; then
+ mv "$stdin" "$stdin.txt"
+ stdin="$stdin.txt"
+ fi
set dummy "$stdin"
shift
elif [ "$inputxclip" = 1 ] ; then