diff --git a/README.md b/README.md index 18cdda2..f092d26 100644 --- a/README.md +++ b/README.md @@ -62,10 +62,18 @@ $ gconftool -t str --set /desktop/gnome/keybindings/vim-anywhere/binding > ~/.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 diff --git a/VimAnywhere-CopyClipboard.workflow/Contents/Info.plist b/VimAnywhere-CopyClipboard.workflow/Contents/Info.plist new file mode 100644 index 0000000..1536c6c --- /dev/null +++ b/VimAnywhere-CopyClipboard.workflow/Contents/Info.plist @@ -0,0 +1,18 @@ + + + + + NSServices + + + NSMenuItem + + default + VimAnywhere-CopyClipboard + + NSMessage + runWorkflowAsService + + + + diff --git a/VimAnywhere-CopyClipboard.workflow/Contents/QuickLook/Preview.png b/VimAnywhere-CopyClipboard.workflow/Contents/QuickLook/Preview.png new file mode 100644 index 0000000..0af59d9 Binary files /dev/null and b/VimAnywhere-CopyClipboard.workflow/Contents/QuickLook/Preview.png differ diff --git a/VimAnywhere-CopyClipboard.workflow/Contents/document.wflow b/VimAnywhere-CopyClipboard.workflow/Contents/document.wflow new file mode 100644 index 0000000..0f4aac0 --- /dev/null +++ b/VimAnywhere-CopyClipboard.workflow/Contents/document.wflow @@ -0,0 +1,197 @@ + + + + + AMApplicationBuild + 346 + AMApplicationVersion + 2.3 + AMDocumentVersion + 2 + actions + + + action + + AMAccepts + + Container + List + Optional + + Types + + com.apple.cocoa.string + + + AMActionVersion + 2.0.3 + AMApplication + + Automator + + AMParameterProperties + + COMMAND_STRING + + CheckedForUserDefaultShell + + inputMethod + + shell + + source + + + AMProvides + + Container + List + Types + + com.apple.cocoa.string + + + ActionBundlePath + /System/Library/Automator/Run Shell Script.action + ActionName + Shell-Skript ausführen + ActionParameters + + COMMAND_STRING + $HOME/.vim-anywhere/bin/run -c + CheckedForUserDefaultShell + + inputMethod + 1 + shell + /bin/bash + source + + + BundleIdentifier + com.apple.RunShellScript + CFBundleVersion + 2.0.3 + CanShowSelectedItemsWhenRun + + CanShowWhenRun + + Category + + AMCategoryUtilities + + Class Name + RunShellScriptAction + InputUUID + 6FFA24CD-4E05-4C6A-A6FB-E32CF835C918 + Keywords + + Shell + Skript + Befehl + Ausführen + Unix + + OutputUUID + 38133079-F4E2-4D5F-9B21-6BBAFABD7CE9 + UUID + B374B8A3-8D8E-4327-9A92-826742A01517 + UnlocalizedApplications + + Automator + + arguments + + 0 + + default value + 0 + name + inputMethod + required + 0 + type + 0 + uuid + 0 + + 1 + + default value + + name + source + required + 0 + type + 0 + uuid + 1 + + 2 + + default value + + name + CheckedForUserDefaultShell + required + 0 + type + 0 + uuid + 2 + + 3 + + default value + + name + COMMAND_STRING + required + 0 + type + 0 + uuid + 3 + + 4 + + default value + /bin/sh + name + shell + required + 0 + type + 0 + uuid + 4 + + + isViewVisible + + location + 309.500000:450.000000 + nibPath + /System/Library/Automator/Run Shell Script.action/Contents/Resources/German.lproj/main.nib + + isViewVisible + + + + connectors + + workflowMetaData + + serviceInputTypeIdentifier + com.apple.Automator.nothing + serviceOutputTypeIdentifier + com.apple.Automator.nothing + serviceProcessesInput + 0 + workflowTypeIdentifier + com.apple.Automator.servicesMenu + + + diff --git a/bin/run b/bin/run index 2515702..c2b0fb3 100755 --- a/bin/run +++ b/bin/run @@ -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 ### @@ -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 @@ -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 diff --git a/install b/install index 0e988de..513f7d4 100755 --- a/install +++ b/install @@ -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 diff --git a/uninstall b/uninstall index a9f1201..b4e934e 100755 --- a/uninstall +++ b/uninstall @@ -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!"