Unity 命令运行器

Unity 命令运行器

我正在寻找 Unity 的命令运行器。我知道快捷键ALT+下有默认运行器F2。但正如该问题所解释的那样运行命令不运行命令行程序它不允许在没有在命令中添加一些前缀的情况下运行命令行程序。

简而言之,我正在寻找命令运行器:

  • 具有自动完成功能
  • 具有最后使用命令的历史记录
  • 允许运行两个命令vim test.txtgedit test.txt不运行任何前缀、后缀等。
  • 如果运行了命令行程序,则退出程序后应关闭终端窗口

我检查了不同的命令运行器gmrun,但没有自动完成或历史xfrun4记录。另一方面,正如在Xfce4 Alt F2 - xfrun4 命令在 14.04 Trusty 中无效需要一些“!”前缀才能工作。

您是否知道一些可以与 Unity 集成并满足该要求的命令运行器?

答案1

使用 gnome-terminal 创建您自己的命令运行器:

首先创建一个文件$HOME/.cmdrunrc

内容应该是:

# include .bashrc to load aliases from the .bashrc in the command runner
source .bashrc

# create a separated history file for the command runner
HISTFILE=~/.cmdrun_history

# shorten the command prompt
PS1='\w\$ '

# function to check an array if it contains an element
containsElement () {
  local e
  for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done
  return 1
}

# your guis which will not open a additional terminal window on execution 
guis=(firefox mousepad gedit geany leafpad nautilus thunar pcmanfm xterm) 

# after this commands finished the terminal will be closed automatically  
close_after=(vi nano top)

# the function that will be executed with every command
custom_run() { 
    if [ -n "$*" ]; then   
        # write the real command to the history without "custom_run" 
        history -s "$*"
        history -a

        # check if the command is an alias
        pure_cmd=$(echo "$*" | xargs | cut -d' ' -f1)
        if [ $(type -t "$pure_cmd") == "alias" ]; then
            # get the real command from the alias
            pure_cmd=$(type "$pure_cmd" | grep -oP "(?<=»)[^']+(?=«)")
            pure_cmd=$(echo "$pure_cmd" | cut -d' ' -f1)
        fi

        # check if command opens a gui or should be closed after it finished
        if containsElement "$pure_cmd" "${guis[@]}"; then
            bash -ic "($* &) &>/dev/null"
        elif containsElement "$pure_cmd" "${close_after[@]}"; then
            gnome-terminal -x bash -ic "$*"
        else
            gnome-terminal -x bash -ic "$*; bash"
        fi
    else
        # remove last command ("custom run") from history, if nothing is entered
        history -d $((HISTCMD-1))
    fi
    exit 0
}

# write the function "custom_run" before every command if the user presses return
bind 'RETURN: "\e[1~ custom_run "\e[4~"\n"'

然后使用以下命令创建一个 .desktop 文件或一个 shell 脚本:

gnome-terminal --title="Command Runner" --hide-menubar --geometry="50x1" -x bash -ic "cd ~; bash --rcfile .cmdrunrc"

相关内容