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

-c option for vim-anywhere #69

Open
wants to merge 13 commits 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
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,18 @@ $ gconftool -t str --set /desktop/gnome/keybindings/vim-anywhere/binding <custom

*I3WM*

Note that in i3, Alt is denoted Mod1: [i3 modifier keys](https://i3wm.org/docs/userguide.html#keybindings).

This allows the use of $mod + Alt + v to open vim for editing:
```bash
$ echo "bindsym $mod+Mod1+v exec ~/.vim-anywhere/bin/run" >> ~/.i3/config # remember to reload your config after
```
On some installations (e.g., Arch), the i3 config file may be at ~/.config/i3/config.
The following (adding Shift) allows you to start the vim session with the contents of the clipboard already open (which is useful if you would like to edit the contents of a text field):
```bash
$ echo "bindsym $mod+Alt+v exec ~/.vim-anywhere/bin/run" >> ~/.i3/config # remember to reload your config after
$ echo "bindsym $mod+Mod1+Shift+v exec ~/.vim-anywhere/bin/run -c" >> ~/.i3/config # remember to reload your config after
```
Adjust in case `$mod` is not set to ctrl.


## History

Expand Down
18 changes: 18 additions & 0 deletions VimAnywhere-CopyClipboard.workflow/Contents/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSServices</key>
<array>
<dict>
<key>NSMenuItem</key>
<dict>
<key>default</key>
<string>VimAnywhere-CopyClipboard</string>
</dict>
<key>NSMessage</key>
<string>runWorkflowAsService</string>
</dict>
</array>
</dict>
</plist>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
197 changes: 197 additions & 0 deletions VimAnywhere-CopyClipboard.workflow/Contents/document.wflow
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>AMApplicationBuild</key>
<string>346</string>
<key>AMApplicationVersion</key>
<string>2.3</string>
<key>AMDocumentVersion</key>
<string>2</string>
<key>actions</key>
<array>
<dict>
<key>action</key>
<dict>
<key>AMAccepts</key>
<dict>
<key>Container</key>
<string>List</string>
<key>Optional</key>
<true/>
<key>Types</key>
<array>
<string>com.apple.cocoa.string</string>
</array>
</dict>
<key>AMActionVersion</key>
<string>2.0.3</string>
<key>AMApplication</key>
<array>
<string>Automator</string>
</array>
<key>AMParameterProperties</key>
<dict>
<key>COMMAND_STRING</key>
<dict/>
<key>CheckedForUserDefaultShell</key>
<dict/>
<key>inputMethod</key>
<dict/>
<key>shell</key>
<dict/>
<key>source</key>
<dict/>
</dict>
<key>AMProvides</key>
<dict>
<key>Container</key>
<string>List</string>
<key>Types</key>
<array>
<string>com.apple.cocoa.string</string>
</array>
</dict>
<key>ActionBundlePath</key>
<string>/System/Library/Automator/Run Shell Script.action</string>
<key>ActionName</key>
<string>Shell-Skript ausführen</string>
<key>ActionParameters</key>
<dict>
<key>COMMAND_STRING</key>
<string>$HOME/.vim-anywhere/bin/run -c</string>
<key>CheckedForUserDefaultShell</key>
<true/>
<key>inputMethod</key>
<integer>1</integer>
<key>shell</key>
<string>/bin/bash</string>
<key>source</key>
<string></string>
</dict>
<key>BundleIdentifier</key>
<string>com.apple.RunShellScript</string>
<key>CFBundleVersion</key>
<string>2.0.3</string>
<key>CanShowSelectedItemsWhenRun</key>
<false/>
<key>CanShowWhenRun</key>
<true/>
<key>Category</key>
<array>
<string>AMCategoryUtilities</string>
</array>
<key>Class Name</key>
<string>RunShellScriptAction</string>
<key>InputUUID</key>
<string>6FFA24CD-4E05-4C6A-A6FB-E32CF835C918</string>
<key>Keywords</key>
<array>
<string>Shell</string>
<string>Skript</string>
<string>Befehl</string>
<string>Ausführen</string>
<string>Unix</string>
</array>
<key>OutputUUID</key>
<string>38133079-F4E2-4D5F-9B21-6BBAFABD7CE9</string>
<key>UUID</key>
<string>B374B8A3-8D8E-4327-9A92-826742A01517</string>
<key>UnlocalizedApplications</key>
<array>
<string>Automator</string>
</array>
<key>arguments</key>
<dict>
<key>0</key>
<dict>
<key>default value</key>
<integer>0</integer>
<key>name</key>
<string>inputMethod</string>
<key>required</key>
<string>0</string>
<key>type</key>
<string>0</string>
<key>uuid</key>
<string>0</string>
</dict>
<key>1</key>
<dict>
<key>default value</key>
<string></string>
<key>name</key>
<string>source</string>
<key>required</key>
<string>0</string>
<key>type</key>
<string>0</string>
<key>uuid</key>
<string>1</string>
</dict>
<key>2</key>
<dict>
<key>default value</key>
<false/>
<key>name</key>
<string>CheckedForUserDefaultShell</string>
<key>required</key>
<string>0</string>
<key>type</key>
<string>0</string>
<key>uuid</key>
<string>2</string>
</dict>
<key>3</key>
<dict>
<key>default value</key>
<string></string>
<key>name</key>
<string>COMMAND_STRING</string>
<key>required</key>
<string>0</string>
<key>type</key>
<string>0</string>
<key>uuid</key>
<string>3</string>
</dict>
<key>4</key>
<dict>
<key>default value</key>
<string>/bin/sh</string>
<key>name</key>
<string>shell</string>
<key>required</key>
<string>0</string>
<key>type</key>
<string>0</string>
<key>uuid</key>
<string>4</string>
</dict>
</dict>
<key>isViewVisible</key>
<true/>
<key>location</key>
<string>309.500000:450.000000</string>
<key>nibPath</key>
<string>/System/Library/Automator/Run Shell Script.action/Contents/Resources/German.lproj/main.nib</string>
</dict>
<key>isViewVisible</key>
<true/>
</dict>
</array>
<key>connectors</key>
<dict/>
<key>workflowMetaData</key>
<dict>
<key>serviceInputTypeIdentifier</key>
<string>com.apple.Automator.nothing</string>
<key>serviceOutputTypeIdentifier</key>
<string>com.apple.Automator.nothing</string>
<key>serviceProcessesInput</key>
<integer>0</integer>
<key>workflowTypeIdentifier</key>
<string>com.apple.Automator.servicesMenu</string>
</dict>
</dict>
</plist>
18 changes: 17 additions & 1 deletion bin/run
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,18 @@ require_file_exists() {
# opts
###

while getopts ":v" opt; do
while getopts ":v:c" opt; do
case "$opt" in
v) set -x ;;
# This can be used to read the clipboard to the temp file
# before Vim starts:
c) READ_CLIPBOARD="yes";;
\?) echo "Invalid option: -$OPTARG" >&2 ;;
esac
done

echo $READ_CLIPBOARD

###
# run
###
Expand All @@ -56,6 +61,10 @@ touch $TMPFILE
# Linux
if [[ $OSTYPE == "linux-gnu" ]]; then
chmod o-r $TMPFILE # Make file only readable by you
# This copies the contents of the clipboard to $TMPFILE:
if [[ $READ_CLIPBOARD == "yes" ]]; then
xclip -o -selection clipboard > $TMPFILE
fi
gvim $VIM_OPTS $TMPFILE
cat $TMPFILE | xclip -selection clipboard

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

# if the -c option is set then on OSX this will copy the clipboard to TMPFILE
if [[ $READ_CLIPBOARD=="yes" ]]; then
# @naydichev's line for OSX: this copies the clipboard to the $TMPFILE
LANG=en_US.UTF-8 pbpaste > $TMPFILE
fi

$mvim_path $VIM_OPTS $TMPFILE
# todo, fix invalid file
# -c option for reading the clipboard has not yet been implemented here

# NOTE
# Here we set LANG explicitly to be UTF-8 compatible when copying text. The only way that was explicitly
Expand Down
2 changes: 2 additions & 0 deletions install
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ elif [[ $OSTYPE == "darwin"* ]]; then
# install the workflow as a service
mkdir -p $HOME/Library/Services
cp -R $AW_PATH/VimAnywhere.workflow $HOME/Library/Services
# This adds the OSX workflow that copies the clipboard contents to the TMPFILE before launching vim:
cp -R $AW_PATH/VimAnywhere-CopyClipboard.workflow $HOME/Library/Services

# TODO: add shortcut
# It would be great if there was a way to set the keyboard shortcut for
Expand Down
2 changes: 2 additions & 0 deletions uninstall
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ if [[ $OSTYPE == "linux-gnu" ]]; then
# OSX uninstall
elif [[ $OSTYPE == "darwin"* ]]; then
rm -rf $HOME/Library/Services/VimAnywhere.workflow
# Removed the workflow that copies the clipboard first:
rm -rf $HOME/Library/Services/VimAnywhere-CopyClipboard.workflow
fi

echo "vim-anywhere has been successfully uninstalled!"