LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 11-29-2009, 05:34 PM   #1
hippiejake
LQ Newbie
 
Registered: Aug 2009
Location: Bakersfield
Distribution: Slackware
Posts: 6

Rep: Reputation: 0
Keyboard shortcuts within terminal?


Hi, is it possible to configure the shell [in xterm, tty, whatever] to recognize custom shortcuts? That is, can I bind any program to Ctrl+X, Alt+X, etc. shortcuts? I know how to do this with Gnome/KDE/Fluxbox, but I'm interested in doing it on a shell. Thanks.
 
Old 11-29-2009, 05:54 PM   #2
raju.mopidevi
Senior Member
 
Registered: Jan 2009
Location: vijayawada, India
Distribution: openSUSE 11.2, Ubuntu 9.0.4
Posts: 1,155
Blog Entries: 12

Rep: Reputation: 92
My shell is "KONSOLE 1.6.6 using KDE 3.5.9 openSUSE 11.0) .
It has the options to modify the control and to user defined controlls.
Settings -> configure shortcuts.
these shortcuts are for ....clearing history
making new session
moving to another tab of the shell
open new shell as root
find a term within the shell
 
Old 11-29-2009, 06:22 PM   #3
hippiejake
LQ Newbie
 
Registered: Aug 2009
Location: Bakersfield
Distribution: Slackware
Posts: 6

Original Poster
Rep: Reputation: 0
KHotkeys is part of KDE. It won't work in any other desktop environment, much less without X.
Scouring some manpages, it looks like it is possible to do it with GNU Screen, editing ~/.screenrc to use the bind and bindkey commands to run an exec command. But it seems sort of hackish and depends on screen [although I have no problem with screen].

So adding "bind ' ' exec mpc toggle" makes ^a <space> executes "mpc toggle" and "bindkey -t ' ' exec mpc toggle" does the same but without escaping first with ^a [very painful to have the music pause every time you hit the spacebar =P]. Although this requires screen, it's pretty cool.

Can anybody do this without screen? I'm pretty happy as is, but there's bound to be more than one way to do it.

Last edited by hippiejake; 11-29-2009 at 06:44 PM.
 
Old 11-29-2009, 06:55 PM   #4
GrapefruiTgirl
Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
Interest in the OP's question got me on a search which led to the bash built-in "bind" function, which is detailed on or about line 3300 or so, in the bash man page. It works in conjunction with the readline library, and in conjunction with the /etc/inputrc config file (or ~/.inputrc).

To try out the OP's idea of launching an application from the console with a shortcut, I bound the sequence CTRL-b CTRL-b to the execution of my firewall script, like so:

shell$ bind -x '"\C-b\C-b":/etc/rc.d/lutelwall/rc.lutelwall.003 start'

and now, if I hit CTRL-b twice, the script executes (well, I did this as regular user, so as you can see, it actually didn't execute; but you get the idea):
Quote:
root@reactor:/etc/rc.d/lutelwall# bind -x '"\C-b\C-b":/etc/rc.d/lutelwall/rc.lutelwall.003 start'
root@reactor:/etc/rc.d/lutelwall#
bash: /etc/rc.d/lutelwall/rc.lutelwall.003: Permission denied
root@reactor:/etc/rc.d/lutelwall#
It also works (or course) from the text VT.

Check out the man page for readline, and the bash man page lines 3300+ in the bash-builtin department, and for more complicated sequences, including making executable functions mapped to shortcut keys, read about /etc/inputrc.

Sasha
 
Old 11-29-2009, 07:24 PM   #5
hippiejake
LQ Newbie
 
Registered: Aug 2009
Location: Bakersfield
Distribution: Slackware
Posts: 6

Original Poster
Rep: Reputation: 0
This only works through the shell, so it would fail in vim, emacs, lynx, etc.
I think this would require something between stdin and the application.
Still very nice, though. Thank you very much!
 
Old 11-29-2009, 07:36 PM   #6
GrapefruiTgirl
Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
OK, so you want to (please explain if I'm wrong here).. Be able to send signals (or whatever) to running applications, like emacs for example, using console shortcuts?

If that's a correct deduction, I think the same would work, as long as the running application has a client-daemon running that listens for commands. Examples are xscreensaver-command, emacsclient, kfmclient and likely lots of others including audio/movie players. Checking the output of `ps` and looking for clients you can talk to would be one way to see if there's a client you can talk to.

I don't use emacs much, but you might find some further interesting reading over here: http://www.internetling.com/2008/11/...-unix-systems/

and particularly regarding emacs, one responder on that (blog?) wrote (the last reply on the page):

Quote:
Hey ! So cool apps !
A few word about how I use emacs into the terminal :
_ launch emacs -nw (create an alias for this, for example cemacs)
_ minimize it with C-z, allright
_ then you would type “fg %emacs” to re-open it : too long
so create a keybinding in your .bashrc like “bind -x ‘”\C-x\C-e”:fg %emacs’”
So you just have to press C-x-e
_ be careful of interference problems if you open another emacs instance. So you may want to use emacsclient
cemacs () { #in .bashrc
if (ps|grep emacs); then
cecho $j “Beware, emacs’s already running :) ”;
echo “let’s open these files in the same session anyway”
sleep 1
emacsclient -n $@
fg %emacs
else emacs -nw $@
fi
}

and in your .emacs :
(server-start)
_ now it’s useful and very powerful !

Then I use 2 scripts to listen some music with mplayer :
_ to listen in shuffle mode, use these in a script :
find $@ ./ -iname “*.mp3″ -o -iname “*.wma” -o -iname “*.ogg” -o -iname “*.m4a” -o -iname “*.wav” \
|grep -i -v INCOM >my_playlist
mplayer -shuffle -playlist my_playlist

_ and then a customized find function to find and play files quickly in all the subtrees of your dir, but it’s a bit long :p But this is really quicker than GUIs.
..which you may be able to adapt to some of your needs.

Sasha

Last edited by GrapefruiTgirl; 11-29-2009 at 07:39 PM.
 
Old 11-30-2009, 10:41 AM   #7
hippiejake
LQ Newbie
 
Registered: Aug 2009
Location: Bakersfield
Distribution: Slackware
Posts: 6

Original Poster
Rep: Reputation: 0
Not really. While using bind with bash is very useful, it won't work within any other interactive program such as vim, elinks, make menuconfig, etc. because bash isn't receiving the input.
This still works in GNU Screen because it acts as an intermediary with input/output to every program run in it [including bash]. This is why Ctrl+a "does stuff" no matter what is going on. I'm starting to think something like this is necessary to have global hotkeys that retain binding within every application.
Without screen or similar, the next best thing I can come up with is Ctrl+z stopping a process to get back to bash, :!bash within vim or the like.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
keyboard shortcuts (any know-how on how to do this) 1dude1 Linux - Software 2 08-07-2006 03:17 PM
KDE Keyboard Shortcuts with different Keyboard Layout hellblade Linux - Software 5 04-18-2006 12:40 AM
keyboard shortcuts eugen.circa Linux - General 1 06-28-2005 10:05 AM
Assigning keyboard shortcuts to keyboard keys the who Linux - Hardware 3 02-20-2004 09:36 PM
keyboard shortcuts justin19fl Linux - Newbie 1 04-24-2001 02:19 PM


All times are GMT -5. The time now is 05:55 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration