Giter VIP home page Giter VIP logo

ttcopy's Introduction

latest version Build Status

ttcopy: Trans-Terminal Copy/Paste

Provide copying and pasting within multiple hosts through the Web.

Introduction Image

Requirements

  • bash (version 3.2 and more)
  • openssl (version 1.0.1e and more)
  • curl (versin 7.19.7 and more)

Installation

Set up ttcopy on the hosts which you want to make share same data. Please follow the following instructions to install it.

With zplug (for zsh users)

If you are using zplug, it is easy and recommended way. Add this line to .zshrc.

zplug "greymd/ttcopy"

That's all 🎉.

With Homebrew (for macOS users)

$ brew tap greymd/ttcopy
$ brew install ttcopy

With apt-get (For Ubuntu users)

# If necessary, install `add-apt-repository` command.
$ sudo apt-get install software-properties-common

# For Ubuntu 12.04: $ sudo apt-get install python-software-properties 

$ sudo add-apt-repository ppa:ttcopy/ppa
$ sudo apt-get update
$ sudo apt-get install ttcopy

Manual Installation

If you cannot choose any of above ways, follow below steps

1. Clone repository

$ git clone https://github.com/greymd/ttcopy.git ~/ttcopy

2. Edit .bashrc or .zshrc

Add following lines.

source ~/ttcopy/ttcp_activate.sh
For advanced users

ttcp_activate.sh adds ttcocpy/bin to $PATH. Instead of using it, you can copy ttcopy/bin and ttcopy/lib somewhere you want to place then make sure ttcopy/bin be listed under $PATH.

For example,

cp -rf ~/ttcopy/bin ~/ttcopy/lib /usr/local

echo "export PATH=$PATH:/usr/local/bin" >> ~/.zshrc" # if you need

Configuration

First of all, ttcopy command displays the screen to let you set default ID and Password. Please prepare ID and Password as you like. Be lazy! You are NOT required to register them on any services. The data you copied can be pasted within the hosts having same ID and Password.

$ ttcopy
Set default ID/Password.
Enter ID for ttcopy/ttpaste: myid001   #<= Enter your ID ("myid001" is just an example).
Enter password for ttcopy/ttpaste:    #<= Enter your password.
Enter same password again:            #<= Enter again.

Created credential file '/home/user/.config/ttcopy/config'
Execute 'ttcopy --init' to show this screen again.

Examples

Copy & Paste within multiple hosts!

  • Host1
$ echo foobar | ttcopy
  • Host2
$ ttpaste
foobar

Clip binary data.

  • Host1
$ cat image.jpg | ttcopy
  • Host2
$ ttpaste | file -
/dev/stdin: JPEG image data, JFIF standard 1.01

Features

Options

ttcopy and ttpaste commands support following options.

$ ttcopy --help
  Usage: ttcopy [OPTIONS]

  OPTIONS:
  -h, --help                         Output a usage message and exit.
  -V, --version                      Output the version number of ttcopy and exit.
  -i ID, --id=ID                     Specify ID to identify the data.
  -p PASSWORD, --password=PASSWORD   Specify password to encrypt/decrypt the data.
  --init                             Set default ID and password.

Use non-default ID and password.

$ seq 10 | ttcopy -i abcdef -p ghijklmn
Copied!
$ ttpaste -i abcdef -p ghijklmn
1
2
3
4
5
6
7
8
9
10

Copy/Paste through proxy server

Commands load shell variable TTCP_PROXY as their proxy server for connection.

$ echo ABCDEFG | TTCP_PROXY="http://example.proxy.server1.com:1234" ttcopy
$ TTCP_PROXY="http://example.proxy.server2.com:5678" ttpaste
ABCDEFG

It is helpful to add this line to .bashrc or .zshrc if you are always using specific proxy server.

export TTCP_PROXY="http://example.proxy.server1.com:1234"

LICENSE

This is available as open source under the terms of the MIT License.

ttcopy's People

Contributors

greymd avatar mecab avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

ttcopy's Issues

wpbcopy should show error message if failed

Currently, "Copied!" is shown even if the upload was failed actually.
It will make the user be confused.

To reproduce:

  1. Make the computer offline

  2. Do the following

echo hogehoge | wpbcopy
  1. You will see "Copied!"

Refactoring: namespace

Most of the functions and variables in wpb.sh should not be called by user.
How about adding prefix them to tell them as "private" and used in wpb.

Proposals

  • public variables: $WPB_ID
  • private variables: $_WPB_PIPE
  • public functions: wpbcopy()
    (No prefix. Also need to consider #11 )
  • private functions: __wpb::spin()

They are referred from zplug.

Sorting out exit status.

My suggestion about the rule related to the exit status.
How about follow the following rules AS MUCH AS POSSIBLE.

  • exit command should be declared in the executable command files (in our case, ttcopy.sh or ttpaste.sh).
  • Let's follow the way of numbering given by general command (like sed, grep).
  • For our original purpose, let's avoid to use 1 - 2, 126 - 165, and 255.
    FYI: http://tldp.org/LDP/abs/html/exitcodes.html

For commands (ttcopy and ttpaste)

Description Exit status Note
Exit successfully 0
Undefined or General errors 1 something undefined for future use.
TTCP_ID/TTCP_PASSWORD is undefined 3
Invalid option/argument 4 same as GNU sed
Nothing has been copied yet. 5
Failed to upload the content. 6 transfer.sh might be down.
Failed to get the content url. 7 cl1p.net might be down.
openssl got something wrong. 8 Maybe, invalid password?
Necessary commands are not found 127 we can use it.. maybe.. http://stackoverflow.com/questions/1763156/127-return-code-from
Terminated by Ctl-C 130 Try $ cat and type Ctrl-c.

For function (like __ttcp::opts, __ttcp::is_env_ok)

Description Exit status Note
success and allow to continue procedure. 0 return 0
let command exit successfully 254 return 254 i.e, --help and --version options.
Other is same as commands. N/A i,e, if the function supposed that the command exits with 4, the function should exit with return 4.

終了ステータスって探しても標準的なルールなかったので、あとは決めで良いのではという気がしている。

Options to set ID/Password

Personally I want new features like them.

  • Host1
$ echo aaa | ttcopy -i my_username -p my_password
  • Host2
$ ttpaste -i my_username -p my_password
aaa

Encrypt transfer.sh URL for cl1p.net

For now, ttcopy post the raw URL given by transfer.sh to cl1p.net.
In order to strengthen the encryption, it is worth encrypting the URL.
As you may know, cl1p.net is only handles plain text, so base64 encoding is required.

I made develop-2.0.0 branch for #28 . I would like to resolve this issue at the same branch.

Strengthen testing

As you may know, ttcopy is depending on the curl and openssl.
It is not yet clear "Which version is already tested ?".
In addition, supported shell version is also not clear.
Any potential bugs like #42 and #45 might be discovered near future.
It is necessary to strengthen the test environment. My suggestion is following.

  • Add test cases for major linux distros

    • There are tons of versions in curl and openssl. It is very troublesome if we try all the combinations between two commands. My idea is run tests on docker containers and try various linux distros.
    • all the official containers of centos https://hub.docker.com/_/centos/
    • all the official containers of ubuntu https://hub.docker.com/_/ubuntu/
  • Add test cases for various bash versions.

    • I noticed that it is not necessary to test for zsh. Because shebang is #!/bin/bash. Even the current shell is in zsh, bash will be used in the ttcopy's child process.
    • I would like to set support version is 3.1 and more. (3.1 seems like PI, that's cool. 3.0 and less is too old).

No I am woking on this issue branch feature/more_test.

Release v1.0 (or 0.9 or something)

I think it already has enough stuff to work at least.

Let's release it now, or let's define the issues which we have to solve before the release.

📛 Reconsider command name ( & repository name).

Excuse me.
Maybe I should create this issue more earlier...

I want to reconsider the name name of wpbcopy and wpbpaste and also the repository name.
They are not bad actually. It expresses the role of those commands well.

However, there are some concerns for me

  • Difficult to type (continuous "w" and "p" keys are troublesome).
  • Lazy to say (especially in Japanese: だぶりゅーぴーびーこぴー?).
    • Not catchy phrase.

How do you think about the current name of repository and command?
Once It is released, it will be very difficult to change and I want to have an opportunity to reconsider it.
if you have any ideas or candidates, let's share it here.
Off course, keeping current name is ok. it is not bad choice.

とても今更なんですが、そもそも名前どうなのってのを考えたく。。
今の名前も悪くはないんですが。


  1. wcopy & wpaste
    First of all, I wondered we can use wcopy and wpaste ( Web + Copy ).
    But unfortunately, the same command is already existing( wcopy ).

  2. rcopy & rpaste
    "r" means "Remote".
    Also it's existing rcopy.

  3. icopy & ipaste
    "i" means "Internet".
    It does not exist, but it sounds like Apple's something...

Proxy connection support

There are three ways.

1. let user set http_proxy orhttps_proxy environment variables.

This is same as wget command.

$ export http_proxy="http://proxy.com:port/"
$ echo aaa | ttcopy # => connecting through the proxy server.

2. Support -x option

This is same as curl command.

$ echo aaa | ttcopy -x http://proxy.com:port/

3. Same as 1, but set original variable TTCP_PROXY.

Personally, I prefer 3.

  • The problems of 1 is, the configuration can conflict with wget.
    • In addition, it is required to detect whether the connection is http or https. it's lazy.
  • In the future, both wget and curl maybe used in order to be compatible with POSIX. The configuration for only either is better to be avoided.

Be compatible with POSIX

I am not a believer of POSIX primitives.
However I hope all the scripts (except for testing) should be compatible with POSIX as much as possible. Because they might be used on the servers which do not have modern commands.

FYI: All the commands compatible with POSIX.
http://qiita.com/richmikan@github/items/e4cb1537d38966c10f4b

I think following changes are needed.

  • Use type command instead of which.
  • Abolish xmllint command and use other commands.

They are not following POSIX, but it seems too much. We need discussion.

  • perl is used as sleep alternatives.
    Actually, perl is installed almost all the servers of UNIX. Even all the BSD has perl in default. If we suppose wpbcopy is used on embedded system, we should abolish it. But it is too much I think.

  • curl is used to API call.
    Ideally, we should check the existence of wget, curl and fetch command and choose it. I think it is worth doing. Sometimes, newly installed linux (like docker container) does not have curl.

Process substitution in curl command does not work.

From tweet:
https://twitter.com/FM34311178/status/836378986850590721

### 実行環境①

[root@fmyokosuka .config]# cat /etc/redhat*
CentOS release 6.3 (Final)
[root@fmyokosuka .config]#

http://qiita.com/greymd/items/0384e961802ee593a0c2 より

手動でインストール
:
git clone https://github.com/greymd/ttcopy.git ~/ttpcopy ←これは~/ttcopyでございます。
:
~/.bashrc
source ~/ttcopy/ttcp_activate.sh
export TTCP_PROXY="http://xxxx.xxxx.co.jp:xxxx" ←これを追加しました。

そんでまず試しに同じマシンでttcopyとttpasteやってみたところ以下でした。


[root@fmyokosuka ~]# echo aaa | ttcopy
Copied!
[root@fmyokosuka ~]# ttpaste
bad decrypt
3078026988:error:0606506D:digital envelope routines:EVP_DecryptFinal_ex:wrong final block length:evp_enc.c:589:

gzip: stdin: unexpected end of file
Failed to decode data.
Please check ID/Password and Salt values.
[root@fmyokosuka ~]# openssl version
OpenSSL 1.0.1e-fips 11 Feb 2013
[root@fmyokosuka ~]#

Logo

Cool stuff like

  _____   _____    ___     ___      ___  __   __ 
 |_   _| |_   _|  / __|   / _ \    | _ \ \ \ / / 
   | |     | |   | (__   | (_) |   |  _/  \ V /  
  _|_|_   _|_|_   \___|   \___/   _|_|_   _|_|_  
_|"""""|_|"""""|_|"""""|_|"""""|_| """ |_| """ | 
"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-' 

🤐 gzip compression

gzip command is not in the POSIX.
But I want to support it. Especially, when the delivering data is plain text, large mount of network cost can be reduced.
Let's save energy in order to save the Earth 🌏 🌍 🌎
We can save the world.
Love & Peace.

  • For ttcopy: copress -> encryption -> upload
... cat | gzip | openssl aes-256-cbc -e -pass pass:$TTCP_PASSWORD ...
  • For ttpaste: download -> decryption -> uncompress
... cat "$TTCP_LASTPASTE_PATH" | openssl aes-256-cbc -d -pass pass:$TTCP_PASSWORD | gzip -d

Attention:
When we finished to implement this feature, I think MAJOR version should be incremented.
Because, this feature will lost the downward compatibility (old version ttpaste cannot download the data from new version ttcopy.)

Let wpb.sh update $PATH

As discussed as #8, wpb.sh should put their directory into $PATH, so that the users can use the functions from other programs.

Retry chance never come.

It seems bug.

# Copy
$ seq 100 | ttcopy -i aaaa -p bbbb
Copied!

# Incorrect password at first time.
$ ttpaste -i aaaa -p bbb
bad decrypt.
71168:error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt:/SourceCache/OpenSSL098/OpenSSL098-52.40.1/src/crypto/evp/evp_enc.c:330:
gzip: unknown compression format
Failed to decode data.
Please check ID/Password and Salt values.

# Second chance never happens.
$ ttpaste -i aaaa -p bbbb
Nothing has been copied yet.

Command does not work on Msys.

From this tweet:
https://twitter.com/FM34311178/status/836378986850590721

### 実行環境② (WindowsにGITHUBクライアントというのをInstallしたら勝手に入ったMsys)

fmyokosuka uname -a
MINGW32_NT-6.1 fmyokosuka 2.5.0(0.295/5/3) 2016-03-31 18:26 i686 Msys
fmyokosuka
fmyokosuka git clone https://github.com/greymd/ttcopy.git ~/ttcopy
Cloning into 'C:/Users/fmyokosuka/ttcopy'...
remote: Counting objects: 615, done.
remote: Compressing objects: 100% (57/57), done.
remote: Total 615 (delta 29), reused 0 (delta 0), pack-reused 549
Receiving objects: 100% (615/615), 1.35 MiB | 413.00 KiB/s, done.
Resolving deltas: 100% (317/317), done.
Checking connectivity... done.
fmyokosuka pwd
/c/Users/fmyokosuka
fmyokosuka vi .bashrc
fmyokosuka cat ~/.bashrc
#
source ~/ttcopy/ttcp_activate.sh
export TTCP_PROXY="http://xxxx.xxxx.co.jp:xxxx"
fmyokosuka
fmyokosuka . .bashrc
fmyokosuka ttcopy
Set default ID/Password.
Enter ID for ttcopy/ttpaste: fmyokosuka
Enter password for ttcopy/ttpaste:
Enter same password again:

Created credential file '/c/Users/fmyokosuka/.config/ttcopy/config'
Execute 'ttcopy --init' to show this screen again.
fmyokosuka
fmyokosuka echo aaa | ttcopy
curl: Can't open '/proc/6848/fd/63'!
curl: try 'curl --help' or 'curl --manual' for more information
Failed to upload the content
fmyokosuka

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.