Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add switch to prepopulate vim with the current clipboard contents #99

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ curl -fsSL https://raw.github.com/cknadler/vim-anywhere/master/install | bash
~/.vim-anywhere/uninstall
```

## Options

* `-v`
- Verbose. Echo of every command in the script.
* `-c`
- Clipboard. Pre-populate Vim with the current clipboard contents.

## Keybinding

__OSX:__ ( default = `ctrl+cmd+v` )
Expand Down
13 changes: 12 additions & 1 deletion bin/run
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ require_file_exists() {
# opts
###

while getopts ":v" opt; do
while getopts ":vc" opt; do
case "$opt" in
v) set -x ;;
c)
preprop_from_clipboard='true'
;;
\?) echo "Invalid option: -$OPTARG" >&2 ;;
esac
done
Expand Down Expand Up @@ -56,6 +59,10 @@ touch $TMPFILE
# Linux
if [[ $OSTYPE == "linux-gnu" ]]; then
chmod o-r $TMPFILE # Make file only readable by you
if [ "${preprop_from_clipboard}" = 'true' ]; then
cont=$(xclip -selection clipboard -o)
xclip -selection clipboard -o > $TMPFILE
fi
gvim $VIM_OPTS $TMPFILE
cat $TMPFILE | xclip -selection clipboard

Expand All @@ -72,6 +79,10 @@ elif [[ $OSTYPE == "darwin"* ]]; then
"mvim must have been moved or uninstalled.\nPlease make sure it is" \
"available in your path and then reinstall vim-anywhere."

if [ "${preprop_from_clipboard}" = 'true' ]; then
LANG=en_US.UTF-8 pbpaste > $TMPFILE
fi

$mvim_path $VIM_OPTS $TMPFILE
# todo, fix invalid file

Expand Down