contour icon indicating copy to clipboard operation
contour copied to clipboard

Spawn New terminal in current working directory, and enhancements for compound Actions

Open SuperfastTimeTraveler opened this issue 3 years ago • 12 comments

Abstract

Ctrl-Shift-N, i.e., the NewTerminal Action doesn't open a new terminal in the present working directory. In general, there is no way so that a user can define their own Actions. I am thinking something like xterm's translations in .Xresources, for new key bindings.

Motivation

  • Maybe the NewTerminal action can account for $PWD while spawning a new terminal.
  • Let the user define and/or override Actions like .Xresources translations, so that compound Actions can be defined.

Specification

Example of translations for UXTerm in .Xresources is as follows:

UXTerm.vt100.translations: #override \n\
  Ctrl <Key> minus:        smaller-vt-font() \n\
  Ctrl <Key> plus:         larger-vt-font() \n\
  Ctrl <Key> 0:            set-vt-font(d) \n\
  Shift <KeyPress> Insert: insert-selection(CLIPBOARD) \n\
  Ctrl Shift <Key>V:       insert-selection(CLIPBOARD) \n\
  Ctrl Shift <Key>C:       copy-selection(CLIPBOARD) \n\
  Ctrl Shift <Key>N:       spawn-new-terminal(-class UXTerm -title uxterm -u8 -ti vt340) \n\
  Ctrl Alt <Key>S:         secure() \n\
  Shift <Btn1Up>:          exec-formatted("xdg-open '%t'", PRIMARY) select-start() select-end()

Is something like this possible for Contour as well, using Actions?

SuperfastTimeTraveler avatar Jul 12 '22 09:07 SuperfastTimeTraveler

Hey, many thanks for your interest in Contour. So if NewTerminal doesn't spawn in $PWD right now (talking right out of my head here, IIRC it's simply reading that info from the config, right), then this can be trivially implemented. :+1: Thanks for that idea.

For the second part, I might need to give it some thought and reread, because I think I might not fully understand that just yet.

"Compound Actions" to me reads like being able to run multiple actions on a single shortcut, say Ctrl+N. That is already possible and even part of the example config that's being auto-generated IIRC. Simply have two input mapping lines using the same key binds but different actions. They're all invoked sequentially in order.

If that's not what you meant, I am sorry for that (I'm not native English speaker :) ), I'll try to reread later with some more time :)

christianparpart avatar Jul 12 '22 10:07 christianparpart

@christianparpart iirc I worked on CWD spawn of new terminal, how did it get broken again?

uspasojevic96 avatar Jul 12 '22 11:07 uspasojevic96

@christianparpart Sorry, I had been vague in the second part, as I am not a native English speaker either 😅. What I meant by that is whether it is possible to develop something like xterm's string(string) method, so that we can key-bind it for doing multiple commands, on say, spawning a new terminal.

Some real life example maybe:

  • Someone wants to run just btop on a newly spawned terminal:
    • { mods: [Control, Shift], key: B, action: NewTerminal|RunCommand("btop\n") }
  • Someone just needs to see the rate of cryptocurrencies:
    • { mods: [Control, Shift], key: O, action: NewTerminal|RunCommand("curl rate.sx\n" }

In other words, something like this would lead to a crazy amount of customizability, IMO.

Also, @uspasojevic96, can you direct me to the file/the method in which this functionality was implemented, so that I might also look at it too?

SuperfastTimeTraveler avatar Jul 12 '22 11:07 SuperfastTimeTraveler

This is the PR in question https://github.com/contour-terminal/contour/pull/498

uspasojevic96 avatar Jul 12 '22 11:07 uspasojevic96

Thanks @uspasojevic96. Also, totally unrelated, is it possible to do something like contour +NewTerminal +RunCommand(...) (like, say, nvim --startuptime startup.log +qa), from the command line itself?

Also, I was thinking of building a completion script for contour zsh completion. Someone can then generate completion scripts for each shell, maybe, say, using contour completion zsh >| _contour in .zfunc. Let me know if I should make one.

SuperfastTimeTraveler avatar Jul 12 '22 12:07 SuperfastTimeTraveler

You can do something like contour nvim --startuptime startup.log +qa. But if your command runs for time smaller than early-exit-threshold you get error on terminal that command exited too early. Maybe we can add flag to ignore that error.

Utkarsh-khambra avatar Jul 12 '22 12:07 Utkarsh-khambra

There is no RunCommand action in contour currently.

Utkarsh-khambra avatar Jul 12 '22 12:07 Utkarsh-khambra

Also, I was thinking of building a completion script for contour zsh completion

Oh that would be awesome!

early-exit-threshold 0

... should be disabling that. Seems like it's even that quickly exiting that we're running into a race condition. That I can fix along with the current GUI refactor, I think. :)

christianparpart avatar Jul 12 '22 12:07 christianparpart

@christianparpart iirc I worked on CWD spawn of new terminal, how did it get broken again?

@Utkarsh-khambra let's see if we can make it testable, so it won't accidentally break then. :)

EDIT: if not programmatically from the inside, it can 100% be (made) testable on the CI using some script-fu.

christianparpart avatar Jul 12 '22 15:07 christianparpart

At the moment contour on NewTerminal action spawns it using pwd

Yaraslaut avatar Oct 03 '23 16:10 Yaraslaut

Only on Windows contour doesn't spawn NewTerminal in CWD , see.

Utkarsh-khambra avatar Oct 10 '23 15:10 Utkarsh-khambra

Sounds about right, I did it for macOS

uspasojevic96 avatar Oct 10 '23 15:10 uspasojevic96