Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 使用fzf从目录中查找并执行程序_Bash_Terminal_Fzf - Fatal编程技术网

Bash 使用fzf从目录中查找并执行程序

Bash 使用fzf从目录中查找并执行程序,bash,terminal,fzf,Bash,Terminal,Fzf,我正在尝试创建一个命令行,它可以让我轻松地选择并运行我下载的许多方便实用程序(即appimages)中的一个 例如,此shell命令查找my Downloads目录中的所有可执行文件: find ~/Downloads -maxdepth 1 -perm -111 -type f 我可以通过管道将它们传输到fzf中,但我很难将其转换为一个脚本,该脚本将执行选定的文件,并且可以从我的桌面上运行该脚本。我在这些帮助下找到了答案: 我创建了这个脚本“find-n-exec2.sh”(将它保存在某

我正在尝试创建一个命令行,它可以让我轻松地选择并运行我下载的许多方便实用程序(即appimages)中的一个

例如,此shell命令查找my Downloads目录中的所有可执行文件:

find ~/Downloads -maxdepth 1 -perm -111 -type f

我可以通过管道将它们传输到fzf中,但我很难将其转换为一个脚本,该脚本将执行选定的文件,并且可以从我的桌面上运行该脚本。

我在这些帮助下找到了答案:

我创建了这个脚本“find-n-exec2.sh”(将它保存在某个地方,例如~/Downloads)并且确保更改其可执行权限:

#!/bin/bash
find ~/Downloads -maxdepth 1 -perm -111 -type f | fzf | xargs -I{} lxterminal -e {}
#!/bin/bash
lxterminal --title="test" --command="bash -c '~/Downloads/find-n-exec2.sh'"
然后我创建了第二个脚本“find-n-exec.sh”,并将其保存到我的~/Desktop(同时确保更改其可执行权限):

注意:我使用的是lxterm,所以如果您使用的是xterm或terminal等,请确保对其进行适当的更改

现在我可以从桌面双击“find-n-exec.sh”,它会打开一个窗口,列出我下载目录中的所有可执行文件。。。上/下光标以查找我想要的pgm,然后按enter键。它打开一个新的终端窗口并执行该程序


希望你觉得这个有用

如果要在同一终端中运行命令:

#!/bin/bash

executable=$(find ~/Downloads -maxdepth 1 -perm -111 -type f | fzf)
$executable