-4

I often type | less [ENTER].

I would like to optimize this.

Environment: Ubuntu 20.04

This needs to work for terminals running in the browser, too.

Any idea how I could enter above string with less effort?

It would be super cool, if the CapsLock key could be used for this, since I don't need this key (and it is easy to access with the ten finger touch-typing-system).

guettli
  • 3,113
  • 14
  • 59
  • 110

2 Answers2

5

With xdotool : sudo apt-get install xdotool

  • Go to : Keyboard settings
  • Create a shortcut with :

bash -c ' sleep 0.3; xdotool getactivewindow type " | less" ; xdotool key Return '

  • Bind a key combinaison, for example : Ctrl + Shift + /

Keyboard settings (sorry in french)

To use caps lock key

Try this :

  • Bind your CAPSLOCK to SuperL : setxkbmap -option caps:super, or an other useless key for you (be careful with keys conflicts).
  • Map your command to your new key enter image description here
1F987
  • 771
  • 8
  • Is there a way to use the (otherwise useless) CapsLock key to trigger the xdotool shortcut? CapsLock "L" would be cool. – guettli Apr 09 '22 at 08:06
  • Yes, just trigger the CapsLock key when the prompt wait the key shorcut (tested on Ubuntu 20.04). But I think it's not a really good idea because your keyboard will be capslocked every time you trigger the shortcut, and you need to trigger again to revert capslock (and off course, your command will be resend again, could be a mess !). – 1F987 Apr 09 '22 at 08:56
  • I don't need CapsLock. It would be great if CapsLock could be used for several such cool shortcuts. – guettli Apr 09 '22 at 19:59
  • 1
    It can be tricky to deal with CAPS_LOCK key, but I have edited my answer with a trick (tested on Ubuntu 20.04, french keyboard). – 1F987 Apr 11 '22 at 13:55
  • why is "sleep" needed? – guettli Apr 11 '22 at 14:11
  • If you remove the `sleep` instruction, the behavior can be incorrect. – 1F987 Apr 11 '22 at 14:39
  • Requests for product, service, or learning material recommendations are off-topic because they attract low quality, opinionated and spam answers, and the answers become obsolete quickly. Instead, describe the business problem you are working on, the research you have done, and the steps taken so far to solve it. – djdomi Apr 12 '22 at 17:21
0

Why don't you just use less my_file instead of piping to less ? you could even just add an alias for less so you do not need to type less completly.

alias l=less

yield
  • 731
  • 1
  • 8
  • 24