Scrot 和 Imgur 上传器 bash 脚本

Scrot 和 Imgur 上传器 bash 脚本

我曾经知道如何做到这一点,但却完全忘记了。

所以我使用 scrot,即“scrot '%d/%m-scrot.jpg”。我知道我可以传递一个-e参数来执行一个程序,但这就是我被卡住的地方。

我想使用scrotImgur 上传器 bash 脚本https://gist.github.com/vivien/9768953 并将图片上传到 Imgur。不过我不知道如何用一个命令完成这两项操作。

我想要做的是获取一个 scrot,将其上传到 imgur,然后将 imgur.sh 的标准输出发送到 xclip,以便将 imgur url 添加到我的剪贴板中。

我隐约记得它看起来像这样:scrot '%d/%m-lulzol.jpg' -e imgur $f然后是一些。但它现在xargs无法识别。$f

我不确定如何将上scrot一个命令的输出用作 Imgur 命令的变量。Bash 中是否存在用于上一个命令的标准输出的某种通用变量?正如您所看到的,我不太熟悉 Bash 的内部工作原理或与文件相关的语法。

答案1

我依稀记得它看起来像这样:scrot '%d/%m-lulzol.jpg' -e imgur $f 然后是一些 xargs。但它现在无法识别 $f。

$f正在使用参数替换。听起来你是在 for 循环中使用它,可能类似于for f in $(ls);...

Bash 中是否存在某种用于前一个命令的 stdout 的通用变量?

I/O 重定向. (顺便说一下,BASH 中没有‘通用变量’这样的东西。)

我想要做的是获取一个 scrot,将其上传到 imgur,然后将 imgur.sh 的标准输出发送到 xclip,以便将 imgur url 添加到我的剪贴板中。

我不熟悉imgur.sh,但根据您使用 xargs 的记忆,我会说该命令看起来像这样:
scrot '%d/%m-lulzol.jpg' -e imgur.sh <imagename> | xargs xclip

这将用于在给定图像 (< day >/< month >-lulzol.jpg) 上scrot执行imgur.sh,然后将标准输出 (可能是图像 URL?) 通过管道传输到xargs,后者将其作为参数提供给xclip,后者将其复制到剪贴板。

答案2

man scrot

[...]
       -e, --exec APP
            Exec APP on the saved image.
[...]
SPECIAL STRINGS
       Both the --exec and filename parameters  can  take  format  specifiers
       that  are  expanded by scrot when encountered.  There are two types of
       format specifier. Characters preceded by a  '%'  are  interpretted  by
       strftime(2). See man strftime for examples.  These options may be used
       to refer to the current date and time.  The second kind  are  internal
       to  scrot  and are prefixed by '$' The following specifiers are recog‐
       nised:

       $f image path/filename (ignored when used in the filename)
[...]

因此命令如下:

scrot '%d/%m-scrot.jpg' -e 'imgur $f | xclip'

-e一个无意义的例子只是为了说明即使包含管道,传递给的命令仍然有效:

% scrot -e 'echo $f | grep 2015'
2015-12-02-015014_1366x768_scrot.png
% scrot -e 'echo $f | grep 2016'
% 

相关内容