7

Is there a terminal, or a tool that allows to have the following feature when working in a terminal? I execute a command like find . -name "*.cpp, or compilation of source code that produces some warning or failing output in files. When the command execution is over I can click on file paths and open them in some program, like editor, viewer. I think in some cases it could improve productivity very well.

The only feature similar to this I saw in guake terminal, called "Quick Open".

6
  • That would be nice. As of now I found this: askubuntu.com/a/417934/380067
    – kos
    Oct 21 '15 at 17:10
  • So like in gnome-terminal for website URLs? It underlines them when you hover over a line of output it recognizes as URL and with CTRL+Click or through the right-click context menu, it opens the URL in your default browser. Your question would be the same behaviour for file system paths, I guess (Open directories with Nautilus, open files with specific default viewer - or open containing directory instead?). Right?
    – Byte Commander
    Oct 21 '15 at 17:11
  • Yes you are right.
    – Yuki
    Oct 21 '15 at 17:17
  • @Yuki did you find a "one left click" solution ?
    – ben
    Jun 8 '18 at 10:04
  • Gave up )). No mouse, only keyboard )). Use zsh completion.
    – Yuki
    Jun 8 '18 at 10:18
3

Not a click-only solution, but a select / hit a keystroke / click solution, which on the other hand allows to open any selection (also outside of a terminal) and in different editors (and to do lots of other neat things);

  • Download Colinker from here;

  • Open Terminal by hitting CTRL+ALT+T;

  • Install Colinker's dependencies by running sudo apt-get update && sudo apt-get install openjdk-8-jre xclip;

  • Install Colinker by running unzip ~/Downloads/Colinker-1.0.1.zip && sudo mv ~/Downloads/Colinker-1.0.1 /opt;

  • Edit Colinker's configuration file by running nano /opt/Colinker/config.xml;

    Here's a sample configuration file to open a selection in Gedit:

<Configuration>
    <Env>
        <timerDelay>4000</timerDelay>
        <defaultBrowser>firefox</defaultBrowser>
    </Env>
    <popupMenu>
        <item name="Open with Gedit">
            <program javaEscapeSelectedText="true">
                <location>gedit</location>
                <arg>__SELECTEDTEXT__</arg>
            </program>
        </item>
    </popupMenu>
</Configuration>
  • Bind the execution of Colinker to a keystroke by adding a custom shortcut running the following command:
bash -c "cd /opt/Colinker; java -jar Colinker.jar \"$(xclip -o)\""

That's it! Final result:

Opening Terminal with CTRL+ALT+T

screenshot1

Running find ~/tmp -type f -iname '*.txt'

screenshot2

Selecting "/home/user/tmp/file.txt"

screenshot3

Hitting the keystroke

screenshot4

Clicking "Open with Gedit"

screenshot5

2
  • Thank you @kos, for you answer, do you think it is possible to make file it left-clickable, i.e. with one left mouse click?
    – Yuki
    Oct 23 '15 at 9:04
  • @user41465 If you mean something like URLs, that will require to change gnome-terminal's source code; while probably possible it's also going to be quite demanding. Unless someone did that already, you only chance is probably to start fiddling with gnome-terminal's source code and try to get that working somehow (you may start by looking at the part which does quite the same for URLs, maybe it's not too hard to change it a bit and replicate the same behavior for files, but I wouldn't count on that too much).
    – kos
    Oct 23 '15 at 12:10
3

I personally use keybindings to open file directly from my terminal.

For instance, on my .zshrc :

## Open file on Vscode
# Press f1 --> last selection is a relative path 
bindkey -s '^[OP' 'code \"$(pwd)/$(xclip -o)\"\n'
# Press f2 --> last selection is an absolute path
bindkey -s '^[OQ' 'code \"$(xclip -o)\"\n'

It needs xclip : sudo apt-get install xclip

^[OP is F1 's keycode, using cat -v to find it out.

\n is needed at the end of the micro-script to auto-launch it.

Do not forget to source ~/.zshrc or to relaunch your terminal for changes to take effect.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.