I have recently installed byobu terminal multiplexer, and I found that I am not able to move in a fast way through the terminal. In linux you can do: Control+Arrows (Left/Right). I want to find the same but in byobu.
And I would like to configure it, in order to be able to use Ctrl+Left and Ctrl+Right if it's possible, not other combinations.
Any idea?
I have tried already this: How to make byobu forward-word and backward-word with CTRL+arrow?
But is not working for me.
Ubuntu 13.10
Thanks in advance.
One way to change your key bindings is to edit /usr/share/byobu/keybindings/f-keys.tmux (or edit ~/.byobu/keybindings.tmux).
You will find these lines :
bind-key -n M-Left previous-window
bind-key -n M-Right next-window
M is for Meta, aka the ALT key. Example. Change the lines for :
bind-key -n C-Left previous-window
bind-key -n C-Right next-window
C for Ctrl key (and S for Shift key).
Save, quit, press F5 to reload profile.
Refs : Bybobu doc, Byobu-and-mc, keybindings-in-byobu-using-tmux-backend, tmux
If the Function and other keys are bound to some other program, they won't work. Also, on some OS e.g CentOS, the keys (and their combinations) cease to function.
My solution is to use the bind-key which is Ctrl a to perform different actions. Here are a list of few important shortcuts with bind-key
Help
$ Ctrl-a ?
Create new window
$ Ctrl-a c
Horizontal split
$ Ctrl-a | #Shift + \ = |
Vertical split
$ Ctrl-a %
Rename windows
$ Ctrl-a ,
Move window
$ Ctrl-a .
To move between splits (tested on RHEL)
$ Ctrl-a (arrow-keys)
NOTE: Tested on RHEL/CentOS
Related
I am using a function that I found in YADR which should insert the output of the last command.
# Use Ctrl-x,Ctrl-l to get the output of the last command
zmodload -i zsh/parameter
insert-last-command-output() {
LBUFFER+="$(eval $history[$((HISTCMD-1))])"
}
zle -N insert-last-command-output
bindkey "^X^L" insert-last-command-output
For some reason, it does not seem to work by pressing ctrl-x ctrl-l but running
echo $(eval $history[$((HISTCMD-1))])
command on the terminal does produce the output of the last command.
Running bindkey -M viins shows "^X^L" insert-last-command-output
as one of the entries. Therefore, the function is registered.
I don't really understand how the function works. I think that the variable LBUFFER holds the output of all last commands but when I echo $LBUFFER, it returns the function code.
Can anyone help me get this working?
I finally found a solution.
I had been trying to use the shortcut inside tmux which did not work. However, outside tmux, everything worked. It turns out that tmux will not allow a shortcut with two keys. I changed the shortcut to just alt-L and everything works.
I have a list of mail addresses of friends (.csv) and I want to see if they have public keys stored on pgp keyservers. I want to get this going for Mac.
The pgp part is not the problem, however I can't get my head around the for loop to go through each element in the file...
for add in {cat contacts.csv | grep #}; do gpg --search-keys $add; done
Don't write loops just for running a single command for each line of a file, use xargs instead. cat is also not required here.
This small snippet is doing what you're trying to achieve:
grep # contacts.csv | xargs -n 1 gpg --search-keys
If you insist in the loop, use the right parenthesis $( ... ) runs the command in a subshell):
for add in $( grep # contacts.csv ); do gpg --search-keys $add; done
I answered a similar, but not equal question on the security stack exchange and Stack Overflow, you might also get some inspiration there.
cd .. goes one folder up.
Is there a (one-line) command to go n folders up?
You sure can define a function to do that:
$ go_up() { for i in $(seq $1); do cd ..; done }
$ go_up 3 # go 3 directories up
I am not aware of any command that does that, but it is easy to create one yourself. For example, just add
cdn() {
for ((i=0;i<${1-0};i++))
do
cd ..
done
}
in your ~/.bashrc file, and after you create a new shell you can just run
cdn N
and you will move up by N directories
All right, another really funny answer, that is really a one-liner, to go up 42 parent directories:
cd $(yes ../|head -42|tr -d \\n)
Same as gniourf_gniourf's other answer, it's cd - friendly (and it's just a couple characters longer than the shortest answer).
Replace 42 with your favorite number.
Now that you understood the amazing power of the wonderful command yes, you can join the dark side and use the evil command eval, and while we're at it we can use the terrible backticks:
eval `yes 'cd ..;'|head -42`
This is so far the shortest one-liner, but it's really bad: it uses eval, backticks and it's not cd - friendly. But hey, it works really well and it's funny!
you can use a singleline for loop:..
for i in {1..3}; do cd ../; done
replace the 3 with your n
for example:
m#mariachi:~/test/5/4/3/2/1$ pwd
/home/m/test/5/4/3/2/1
m#mariachi:~/test/5/4/3/2/1$ for i in {1..3}; do cd ../; done
m#mariachi:~/test/5/4$ pwd
/home/m/test/5/4
...however I don't think it will be much faster than typing cd and .. then hitting tab for each level you want to go up!! :)
How often do you go up more than five levels? If the answer is Not too often I suggest you place these cd - friendly aliases in your profile:
alias up2='cd ../..'
alias up3='cd ../../..'
alias up4='cd ../../../..'
alias up5='cd ../../../../..'
Advantages
No bashims, no zshisms, no kshisms.
Works with any shell supporting aliases
As readable and understandable as it gets.
A funny way:
cdupn() {
local a
[[ $1 =~ ^[[:digit:]]+$ ]] && printf -v a "%$1s" && cd "${a// /../}"
}
How does it work?
We first check that the argument is indeed a number (a chain of digits).
We populate the variable a with $1 spaces.
We perform the cd where each space in a has been replaced with ../.
Use as:
cdupn 42
to go up to forty-second parent directory.
The pro of this method is that you'll still be able to cd - to come back to previous directory, unlike the methods that use a loop.
Absolutely worth putting in your .bashrc. Or not.
I'm trying to write a wrapper for qrsh, the Oracle Grid Engine equivalent to rsh, and am having trouble identifying the command given to it. Consider the following example:
qrsh -cwd -V -now n -b y -N cvs -verbose -q some.q -p -98 cvs -Q log -N -S -d2012-04-09 14:02:08 GMT<2012-04-11 21:53:41 GMT -b
The command in this case starts from cvs. My wrapper needs to be general purpose so I can't look specifically for cvs. Any ideas on how to identify it? One thought is to look for executable commands starting from the end backwards, which will work in this case but won't be robust as "cvs" could appear in an option to itself. The only robust option that I can come up with is to fully implement the qrsh option parser but I'm not thrilled about it since it will need to be updated with qrsh updates and is complicated.
One option is to set QRSH_WRAPPER to echo and run qrsh once. However, this then requires two jobs to be issued instead of one, adding latency and wasting a slot.
In zshell how to move forward word, I can set -o vi and use vi format. Is there a way to move forward in zshell by a word
If you're using iTerm2 on OSX, you can use the Natural Text Editing preset under Preferences -> Profile -> Keys.
This supports these key combos (which are very similar to other editors):
alt/option + left = move left one word
alt/option + right = move right one word
The ZLE widget for moving forward by one word is forward-word. Therefore, you may use bindkey to bind this widget to any key you want.
For example,
$> bindkey ^O forward-word
would allow you to move forward by one word when pressing Ctrl-O. Note that ^O is actually a quoted insert of Control followed by O.
Your zsh command prompt works either like emacs or like vi. If it works like vi, put it in command mode (esc) and type w. If it works like emacs, use M-f.
More information available at man zshzle.
Similar to other answers, but for Zsh on iTerm it took me a while to find this:
If you are using Zsh, like Oh My Zsh, in iTerm then go to: Preferences > Profiles > Keys sub-menu
Click + sign
Add your shortcut combo, choose "Send Escape Sequence"
inputs for left and right below.
left:
[1;5D
right:
[1;5C
forward word [Meta]+[f]
backward word [Meta]+[b]
On macOS, [option]+[→] and [option]+[←] work too.
In my zsh terminal it was already set to the below using bindkey
"^[f" forward-word
"^[b" backward-word
I was not sure how to use this, read on Apple Forum's, this is basically
^+[ release it then press f or press esc release it then press f
Similarly for backward,
^+[ release it then press b or press esc release it then press b