mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2025-12-12 01:52:31 +01:00
feat(plugin): Add ghostty-copypaste plugin
This commit is contained in:
parent
c6482fa5be
commit
176d528f97
2 changed files with 58 additions and 0 deletions
43
plugins/ghostty-copypaste/ghostty-copypaste.plugin.zsh
Normal file
43
plugins/ghostty-copypaste/ghostty-copypaste.plugin.zsh
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
function zle-copy-to-clipboard {
|
||||
local selected_text start_pos end_pos
|
||||
|
||||
(( $MARK < $CURSOR ))
|
||||
&& { start_pos=$MARK; end_pos=$CURSOR; }
|
||||
|| { start_pos=$CURSOR; end_pos=$MARK; }
|
||||
|
||||
(( start_pos < 0 || end_pos < 0 ))
|
||||
&& zle -R && return
|
||||
|
||||
selected_text="${BUFFER[$start_pos+1, $end_pos]}"
|
||||
|
||||
command -v xclip &> /dev/null
|
||||
&& ( echo -n "$selected_text" | xclip -selection clipboard )
|
||||
&& zle -R && return
|
||||
|
||||
command -v wl-copy &> /dev/null
|
||||
&& ( echo -n "$selected_text" | wl-copy )
|
||||
&& zle -R && return
|
||||
|
||||
zle -R
|
||||
}
|
||||
|
||||
function zle-paste-from-clipboard {
|
||||
local clipboard_content
|
||||
|
||||
command -v xclip &> /dev/null
|
||||
&& clipboard_content=$(xclip -selection clipboard -o 2>/dev/null)
|
||||
command -v wl-paste &> /dev/null
|
||||
&& clipboard_content=$(wl-paste --no-newline 2>/dev/null)
|
||||
|
||||
[[ -z "$clipboard_content" ]] && return
|
||||
|
||||
LBUFFER+="$clipboard_content"
|
||||
zle -R
|
||||
}
|
||||
|
||||
zle -N zle-copy-to-clipboard
|
||||
zle -N zle-paste-from-clipboard
|
||||
|
||||
# these 2 CSI from ghostty are sent for Ctrl+Shift+C and Ctrl+Shift+V
|
||||
bindkey '^[[99;6u' zle-copy-to-clipboard
|
||||
bindkey '^[[118;6u' zle-paste-from-clipboard
|
||||
Loading…
Add table
Add a link
Reference in a new issue