GithubHelp home page GithubHelp logo

iamfirecracker / cb Goto Github PK

View Code? Open in Web Editor NEW
1.0 3.0 0.0 9 KB

Yet another tool to wrap reads from, and writes to the OS clipboard -- it works from within SSH sessions too!

Shell 96.50% Makefile 3.50%

cb's Introduction

cb

Yet another tool to wrap reads from, and writes to the OS clipboard -- it works from within SSH sessions too!

Backgroud

My life as a developer is a mess: at work I have a laptop with Windows 7 and Cygwin installed; I also have a Vagrant box, running Ubuntu, that I use to do the most of my development work. At home I have a Macbook Air, with Mac OS Sierra.

You can easily imagine how quickly I got tired of having to remember which of the various pbaste, getclip et al. command I should have run depending on which terminal window I had opened.

Wouldn't it be nice if I could read from the OS clipboard, or write to it, using a single command line tool? And wouldn't it awesome if the same tool worked on various operating systems? (at least the ones I use on a daily basis)

enters cb..

Installation

Clone the repo, and run make install:

mkdir -p ~/opt/
cd ~/opt
git clone https://github.com/iamFIREcracker/cb.git
cd cb
PREFIX=~/local/bin make install

Usage

Writing to the OS clipboard is as simple as piping to cb whatever it is that you want to save to the clipboard:

> fortune | cb

Reading from the OS clipboard it's even easier:

> cb
A little suffering is good for the soul.
                -- Kirk, "The Corbomite Maneuver", stardate 1514.0

Advanced usage: remote sessions

Most of the development activities I do at work, I do from a Vagrant box; finding proper Vim and Tmux configurations that play nice with the OS clipboard (especially with remote sessions in the mix) has always been painful, so painful that I decided to ship cb with some painkillers for that.

> cb --listen

This will start a daemon, listening on port 5556 (it's the default, but you can change it by overriding the CB_REMOTE_PORT env variable) for commands to read from or write to the OS clipboard. You might wonder: what's so good about it? Well, you can run it on your host machine (ie. the one with a OS clipboard), change the ssh commands you use to log into your remote dev boxes to do some port forwarding magic:

> ssh -R 5556:localhost:5556 devbox ...

And that's it, running cb from the remote host (well, you will have to get cb installed there too..) will get you the content of the host machine OS clipboard

> cb
A little suffering is good for the soul.
                -- Kirk, "The Corbomite Maneuver", stardate 1514.0

Tmux integration

Add the following to your .tmux.conf:

bind -T copy-mode-vi y      send -X copy-pipe-and-cancel "myreattach-to-user-namespace cb"
bind y run "tmux save-buffer - | myreattach-to-user-namespace cb"

myreattach-to-user-namespace is another wrapper I created to try and make sense of all the different OSes I am dealing with, every day.

Vim integration

Adding the following to your .vimrc will probably do it:

function! g:FuckingCopyTheTextPlease()
    let view = winsaveview()
    let old_z = @z
    normal! gv"zy
    call system('cb', @z)
    let @z = old_z
    call winrestview(view)
endfunction

function! g:FuckingCopyAllTheTextPlease()
    let view = winsaveview()
    let old_z = @z
    normal! ggVG"zy
    call system('cb', @z)
    let @z = old_z
    call winrestview(view)
endfunction

vnoremap <leader>y :<c-u>call g:FuckingCopyTheTextPlease()<cr>
nnoremap <leader>y VV:<c-u>call g:FuckingCopyTheTextPlease()<cr>
nnoremap <leader>Y :<c-u>call g:FuckingCopyAllTheTextPlease()<cr>

nnoremap <leader>p :set paste<CR>:read !cb<CR>:set nopaste<CR><leader>V=
nnoremap <leader>P O<esc>:set paste<CR>:read !cb<CR>:set nopaste<CR>kdd

Borrowed from Steve Losh's awesome vimrc -- thanks for all that!

cb's People

Contributors

iamfirecracker avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.