1

Is it possible to take a keybind/keyboard shortcut and turn it into a CLI command or integrate that keybind/keyboard shortcut into a script that can then be executed in BASH?

I know this would be highly dependent on the terminal emu that one is using. for example: i'm using "terminator", and i want to fullscreen it with a command rather than the F11 keybind that it ships with. i could make a simple alias like this:

alias fullscreen="terminator -f"

the new alias only opens another terminator window in fullscreen, while the F11 keybind fullscreens the current terminator window. ideally, i would want to incorporate the keystroke.

I'm not even sure that this can be done. if there is any other details i am forgetting, just let me know.

2 Answers 2

1

If you want your terminal window to go fullscreen with a terminal command - specially if your goal is to make it terminal independent - you can use wmctrl like this (if you for some reason do not have it installed already just sudo apt-get install wmctr first) :

wmctrl -r :ACTIVE: -b toggle,fullscreen
4
  • This is very helpful for this particular case. but the fullscreen instance was just for an example, so the main question i have still stands. the kbshortcut-to-CLI command could apply in many other ways. so i imagine that it'd be sort of a specialized case-by-case sort of thing, so i suspect that there isn't a universal answer. Commented Nov 6, 2019 at 22:06
  • Actually in that case you can use xdotool like this : xdotool key F11 and this will fire the global shortcut assigned to F11. you could even specify it such that it applies to a different open window than the one you have currently selected. You can try this for example xdotool selectwindow windowfocus key F11 . You will get a special cursor and any window you click on will get a F11 shortcut fired within it. Bear in mind that the selectwindow is just an example and using xdotool search [--name/--class] windowfocus key [F11] lets you fire that shortcut from another terminal.
    – NetIceCat
    Commented Nov 7, 2019 at 20:04
  • Again; very helpful. I will look into both of your suggestions. Thank you. Commented Nov 7, 2019 at 20:39
  • one thing i forgot to mention was that even though xdotool is pretty much the go-to tool for window-mouse-keyboard interactions from a terminal (you can do some neat things with it, including quasi-immitating human mouse-keyboard interaction for some pesky web apps that expect you to keep window in focus while a timer runs down before letting you move onto the next slide ) sometimes may not be installed along with the newest kernels so give sudo apt install xdotool and givexdotool key F11 a try from any terminal window.
    – NetIceCat
    Commented Nov 7, 2019 at 21:10
0

bash allows you to use the bind command to attach a command to a key sequence. So

bind -x '"\ea": ls -l"

sets up the sequence Escape a to run the ls -l command. Depending on your terminal emulator and settings, you probably can probably use a modifier key such as Alt with the a to send this sequence.

This functionality is provided by the readline library. Other programs such as gdb also use this library and it can be configured via the ~/.inputrc file.

As @BarBar1234 has noted, there are a programs that can resize windows, iconify them etc. I like xdotool

For completeness I should mention that terminal programs such as xterm allow you to set up translations which allows, amongst other things, the ability to insert() strings.

1
  • This is also very helpful. I have not yet used the bind command, and it looks like it has way more to it than something as simple as my question. I will give this a try, though, because i can see this custom commands and keybinds as an issue coming up quite a lot in my future. I have xterm installed on my machine, and i intend of switching over to it asap. it has exactly the type of functionality i want. for now, i am stuck using Terminator, so i was hoping to emulate some of the features in xterm. I should probably learn both. Commented Nov 7, 2019 at 21:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .