Zsh Mac OSx Mountain Lion vim promt - zsh

I am wondering if anybody is able to get the vim prompt working properly using Mac OSx Mountain Lion the latest version. I am able to edit in vim mode on the command line but I have seen with zsh before that you can go into Vim mode which launches a vim editor and you can write you command there and then write and quit and it will add it to the next line in the terminal. There may be a plugin to do this I am not sure? Any help would be great.

This answer was posted here:
https://stackoverflow.com/a/903973/1031826
Basically, if you're using vi mode, you can add the following lines to your .zshrc:
autoload -U edit-command-line
zle -N edit-command-line
bindkey -M vicmd v edit-command-line
And you can press ESC-V to edit the current line in whatever your default editor is.
You can adjust the last line ("bindkey...") if you want to change the key binding used.

Related

Configure tmux copy mode to also dump a copy into the system clipboard

When working with multiple panes, it's convenient to use the tmux copy mode (ctrl+b [) to be able to use pane-aware copying. However, copy mode copies into a tmux copy buffer, rather than into the system clipboard. Ideally, I would like a copy to automatically copy into the system clipboard too.
A basic starting point was to add this alias to my bashrc:
alias tmux2clip='tmux save-buffer - | xsel -i -b' (on linux, requires xsel to be installed)
alias tmux2clip='tmux save-buffer - | pbcopy' (on macos)
After I copy using copy mode, I run the alias and the text gets copied into my clipboard! Works like a charm, but always requires that one extra manual step.
It would be ideal, if that alias can trigger as a kind of "post tmux copy hook" that I configure in tmux.
The best thing I could come up with is this line in my ~/.tmux.conf:
bind-key -T copy-mode MouseDragEnd1Pane send-keys -X copy-pipe-and-cancel "xsel -i -b"
# similarly, I believe only needed for keyboard based copies:
bind-key -T copy-mode C-w send-keys -X copy-pipe-and-cancel "xsel -i -b"
bind-key -T copy-mode M-w send-keys -X copy-pipe-and-cancel "xsel -i -b"
This causes any mouse based selection (note: I prefer mouse selection over keyboard based selections) to trigger a copy of that selection into my system clipboard. The annoying thing is though, that it will always happen, i.e. not only in copy mode, just anytime I select something it happens. This turns out to be quite sensitive in practice, just clicking the window with my mouse to give it focus often already accidentally triggers a small selection (often accidentally overwriting existing content in my clipboard, causing me to sometimes paste completely different stuff than intended).
I searched many similar questions but haven't been able to find any satisfying answers. I would really hope to find a way to get a kind of "post tmux copy hook" where I can insert my copy-to-clipboard command.
I use Ubuntu 18.04, with tmux 2.6. Please also be aware that I use mouse mode in my ~/.tmux.conf:
set -g mouse on
Any help would be highly appreciated. I've been wanting this for many months now already, and all of my revived efforts have only led to lost time :(
If you don't want tmux to enter copy mode when you drag on the pane, then unbind MouseDrag1Pane in the root table (unbind -n MouseDrag1Pane).

Can tmux query physical terminal? (Maybe iTerm2 only)

I'm trying to detect the presence of iTerm2 and if I run the following in iTerm2 (echo -n $'\e[5n'; read -s -t 0.1 line; printf '%q\n' "$line") the terminal responds with $'\033'\[ITERM2\ 3.2.1n$'\033'\[0n
However, if I am running a tmux session in the terminal, then tmux responds and gives me nothing.
Any idea how I can ask tmux to query the physical terminal to report its status?
Footnotes
Here is a description of [5n in the tmux source: https://github.com/tmux/tmux/blob/486ce9b09855ae30a2bf5e576cb6f7ad37792699/tools/ansicode.txt#L577
This might be iTerm2 only, since I haven't seen a response on any other terminal
According to ft in freenode's #tmux (and as seen in this Super User answer), you can use:
'\ePtmux;\e" STUFF_FOR_THE_TERMINAL_HERE "\e\\'
So, it would be something like:
echo -n $'\ePtmux;\e\e[5n\e\\'

How to change the terminal title

I'm currently using Hyper terminal on a mac, but this question also applies to other types of terminals, e.g. iTerm
How do you change the terminal title from username#devicename:~ into just ~ or zsh.
Currently my shell is zsh with oh-my-zsh installed. I'm not looking for workarounds through powerline or themes.
One more question:
How do you reset back after running echo -n -e "\033]0;SERVER\007"?
Within ~/.zshrc
Uncomment the following line to disable auto-setting terminal title.
DISABLE_AUTO_TITLE="true"
I'm using this in my .zshrc:
# oh-my-zsh seems to enable this by default, not desired for
# workflow of controlling terminal title.
DISABLE_AUTO_TITLE="true"
function set_terminal_title() {
echo -en "\e]2;$#\a"
}
Have you googled to search for an answer? How about the following:
https://alvinalexander.com/blog/post/mac-os-x/change-title-bar-of-mac-os-x-terminal-window
echo -n -e "\033]0;YOUR TITLE HERE\007"
With iterm 2 3.3.3 there's a setting under preferences->profiles->general-basics->title that you can set to PWD (and a few other options). It seems they changed a few things related to this recently and this overrides whatever is in the .zshrc.
I'm guessing one of these options might turn of this behavior as well. In my case PWD is exactly what I want.
For Mac, first:
brew install wmctrl
then for Mac or Linux
wmctrl -r :ACTIVE: -N "~"
in the active window. Type man wmctrl if you want to say ways to select a window that is not active.
This works for me:
DISABLE_AUTO_TITLE="true"
case $TERM in xterm*)
precmd () {print -Pn "\e]0;%~\a"}
;;
esac

urxvt -cd "/abs/path" not loading user zsh config

When I run urxvt -cd "/absolute/path" to start a terminal in a directory, it doesn't load my user zsh settings, it only loads the global ones in /etc.
Here's some context: Running latest stable versions of rxvt-unicode and zsh (on Arch Linux). I've got ZDOTDIR=~/.zsh in case that makes a difference (but I doubt it, since I tried symlinking ~/.zshrc to ~/.zsh/.zshrc.) If I just run urxvt then it works fine, but it's with the -cd flag that it messes up.
The reason I'm trying to do this is to start a terminal in the current location from Thunar AND have it read my user zsh configuration file. So if you know another way of doing this then that will work too.
Try adding -ls to its options to run it as login shell, like:
urxvt -ls -cd "/absolute/path"
Otherwise it will spawn a subshell. If that doesn't work for you, it still possible to use:
urxvt -e /where/is/your/zsh -i -l -c "cd /where/you/want/it"
Or (regarding the Thunar custom action):
urxvt -cd %f -e /where/is/your/zsh -i -l

How do you switch to zsh when using Nitrous.io

Any ideas? I've tried using :
chsh -s /bin/zsh
But any password I've tried has failed.
You can't use zsh in the main console as you don't have root access, but you could utilize zsh with tmux (which is already installed on your Nitrous box).
You will just need to add this line into ~/.tmux.conf :
set-option -g default-shell /bin/zsh
Once this has been added, start a new tmux session by running:
tmux new -s session_name
Just put zsh at the end of ~/.bashrc to automatically start zsh in the main console when you log in.
Typing exit once will take you back to bash.

Resources