Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
oh-my-zsh
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
github
oh-my-zsh
Commits
3bb23e8e
Unverified
Commit
3bb23e8e
authored
Dec 29, 2021
by
Luiz
Committed by
GitHub
Dec 29, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(transfer): allow encryption of uploads using GPG (#9983)
Co-authored-by:
Marc Cornellà
<
hello@mcornella.com
>
parent
5b2f99bc
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
110 additions
and
65 deletions
+110
-65
README.md
plugins/transfer/README.md
+28
-11
transfer.plugin.zsh
plugins/transfer/transfer.plugin.zsh
+82
-54
No files found.
plugins/transfer/README.md
View file @
3bb23e8e
...
@@ -2,23 +2,40 @@
...
@@ -2,23 +2,40 @@
[
`transfer.sh`
](
https://transfer.sh
)
is an easy to use file sharing service from the command line
[
`transfer.sh`
](
https://transfer.sh
)
is an easy to use file sharing service from the command line
## Usage
To use it, add
`transfer`
to the plugins array in your zshrc file:
Add
`transfer`
to your plugins array in your zshrc file:
```
zsh
```
zsh
plugins
=(
... transfer
)
plugins
=(
... transfer
)
```
```
Then you can:
## Usage
-
transfer a file:
-
Transfer a file:
`transfer file.txt`
.
```
zsh
-
Transfer a whole directory (it will be automatically compressed):
`transfer dir`
.
transfer file.txt
```
-
transfer a whole directory (it will be automatically compressed):
### Encryption / Decryption
```
zsh
-
Encrypt and upload a file with symmetric cipher and create ASCII armored output:
transfer directory/
```
```zsh
transfer file -ca
```
-
Encrypt and upload directory with symmetric cipher and gpg output:
```zsh
transfer directory -ca
```
-
Decrypt file:
```zsh
gpg -d file -ca
```
-
Decrypt directory:
```zsh
gpg -d your_archive.tgz.gpg | tar xz
```
plugins/transfer/transfer.plugin.zsh
View file @
3bb23e8e
# transfer.sh Easy file sharing from the command line
# transfer Plugin
# Usage Example :
# > transfer file.txt
# > transfer directory/
# Author:
# Author:
# Remco Verhoef <remco@dutchcoders.io>
# Remco Verhoef <remco@dutchcoders.io>
# https://gist.github.com/nl5887/a511f172d3fb3cd0e42d
# https://gist.github.com/nl5887/a511f172d3fb3cd0e42d
# Modified to use tar command instead of zip
# Modified to use tar command instead of zip
#
#
curl
--version
2>&1
>
/dev/null
if
[
$?
-ne
0
]
;
then
echo
"Could not find curl."
return
1
fi
transfer
()
{
transfer
()
{
# check arguments
# check arguments
if
[
$#
-eq
0
]
;
if
[[
$#
-eq
0
]]
;
then
then
cat
<<
EOF
echo
"No arguments specified. Usage:
\n
echo transfer /tmp/test.md
\n
cat /tmp/test.md | transfer test.md"
Error: no arguments specified.
Usage: transfer [file/folder] [options]
Examples:
transfer /tmp/test.md
transfer /tmp/test.md -ca
cat /tmp/test.md | transfer test.md
cat /tmp/test.md | transfer test.md -ca
Options:
-ca Encrypt file with symmetric cipher and create ASCII armored output
EOF
return
1
fi
if
((
!
$+
commands[curl]
))
;
then
echo
"Error: curl is not installed"
return
1
return
1
fi
fi
local
tmpfile tarfile item
basename
# get temporarily filename, output is written to this file show progress can be showed
# get temporarily filename, output is written to this file show progress can be showed
tmpfile
=
$(
mktemp
-t
transferXXX
)
tmpfile
=
$(
mktemp
-t
transferXXX
)
# upload stdin or file
# upload stdin or file
file
=
$1
item
=
"
$1
"
# crypt file with symmetric cipher and create ASCII armored output
local
crypt
=
0
if
[[
"
$2
"
=
-ca
]]
;
then
crypt
=
1
if
((
!
$+
commands[gpg]
))
;
then
echo
"Error: gpg is not installed"
return
1
fi
fi
if
tty
-s
;
if
!
tty
-s
;
then
then
# transfer from pipe
basefile
=
$(
basename
"
$file
"
|
sed
-e
's/[^a-zA-Z0-9._-]/-/g'
)
if
((
crypt
))
;
then
gpg
-aco
- | curl
-X
PUT
--progress-bar
-T
-
"https://transfer.sh/
$item
"
>>
$tmpfile
else
curl
--progress-bar
--upload-file
-
"https://transfer.sh/
$item
"
>>
$tmpfile
fi
else
basename
=
$(
basename
"
$item
"
|
sed
-e
's/[^a-zA-Z0-9._-]/-/g'
)
if
[
!
-e
$file
]
;
if
[[
!
-e
$item
]]
;
then
then
echo
"File
$item
doesn't exist."
echo
"File
$file
doesn't exists."
return
1
return
1
fi
fi
if
[
-d
$file
]
;
if
[[
-d
$item
]]
;
then
then
echo
$file
# tar directory and transfer
# tar directory and transfer
tarfile
=
$(
mktemp
-t
transferXXX.tar.gz
)
tarfile
=
$(
mktemp
-t
transferXXX.tar.gz
)
cd
$(
dirname
$file
)
&&
tar
-czf
$tarfile
$(
basename
$file
)
cd
$(
dirname
$item
)
||
{
curl
--progress-bar
--upload-file
"
$tarfile
"
"https://transfer.sh/
$basefile
.tar.gz"
>>
$tmpfile
echo
"Error: Could not change to directory
$(
dirname
$item
)
"
return
1
}
tar
-czf
$tarfile
$(
basename
$item
)
if
((
crypt
))
;
then
gpg
-cao
-
"
$tarfile
"
| curl
--progress-bar
-T
"-"
"https://transfer.sh/
$basename
.tar.gz.gpg"
>>
$tmpfile
else
curl
--progress-bar
--upload-file
"
$tarfile
"
"https://transfer.sh/
$basename
.tar.gz"
>>
$tmpfile
fi
rm
-f
$tarfile
rm
-f
$tarfile
else
else
# transfer file
# transfer file
curl
--progress-bar
--upload-file
"
$file
"
"https://transfer.sh/
$basefile
"
>>
$tmpfile
if
((
crypt
))
;
then
fi
gpg
-cao
-
"
$item
"
| curl
--progress-bar
-T
"-"
"https://transfer.sh/
$basename
.gpg"
>>
$tmpfile
else
else
# transfer pipe
curl
--progress-bar
--upload-file
"
$item
"
"https://transfer.sh/
$basename
"
>>
$tmpfile
curl
--progress-bar
--upload-file
"-"
"https://transfer.sh/
$file
"
>>
$tmpfile
fi
fi
fi
fi
# cat output link
# cat output link
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment