diff --git a/Basic-use-cases.md b/Basic-use-cases.md index 97418b1..9ff30eb 100644 --- a/Basic-use-cases.md +++ b/Basic-use-cases.md @@ -193,6 +193,35 @@ There are several ways to run commands from `nnn`: 2. Use the prompt key to show the prompt and enter your command. The commands are invoked using the `$SHELL` so you can use commands, aliases (in `~/.zshenv` for zsh), environment variables, pipes, redirections. 3. You can also assign keys to arbitrary non-background cli commands (non-shell-interpreted) you use frequently and invoke like plugins. ([instructions](https://github.com/jarun/nnn/tree/master/plugins#running-commands-as-plugin)). +#### Copy command from spawned shell to prompt + +The prompt (non-readline `nnn`-internal one) can remember the last executed command. Sometimes it may be desirable copy a command from shell history to the prompt. Keybinds can be configured to copy a command from bash/zsh prompt to the system clipboard. You can use these at the subshell prompt and paste the command at the prompt with Ctrl-Shift-V. + +```bash +# bash: add to ~/.bashrc to copy current line to clipboard with ^] + +if [[ -n $DISPLAY ]]; then + copy_line_to_x_clipboard () { + printf %s "$READLINE_LINE" | xsel -ib + } + bind -x '"\C-]": copy_line_to_x_clipboard' +fi +``` + +```zsh +# zsh: add to ~/.zshrc +# copy current line to clipboard with ^U + +if [[ -n $DISPLAY ]]; then + x-kill-whole-line () { + zle kill-whole-line + print -rn -- "$CUTBUFFER" | xsel -ib + } + zle -N x-kill-whole-line + bindkey '\C-u' x-kill-whole-line +fi +``` + #### Shell depth indicator If you use `!` to spawn a shell in the current directory and your shell is bash or zsh, it could be nice to add: