Add local file upload
This commit is contained in:
parent
bcb0e1212d
commit
d75236f43c
30
README.md
30
README.md
|
@ -1,5 +1,31 @@
|
|||
# ppsh
|
||||
A simple shell screenshot tool, named after the PPSh,
|
||||
a Soviet submachine gun, because it shoots and ends with `sh`.
|
||||
A simple shell screenshot tool that uploads to an ssh server,
|
||||
named after the PPSh, a Soviet submachine gun, because it shoots and ends with `sh`.
|
||||
|
||||
Replacement for my old python script because finding a maintained SFTP library for Python is more effort than it’s worth.
|
||||
|
||||
## Usage
|
||||
|
||||
```sh
|
||||
ppsh
|
||||
```
|
||||
|
||||
to capture a screenshot and upload it or
|
||||
|
||||
```sh
|
||||
ppsh file.png
|
||||
```
|
||||
|
||||
to upload `file.png` to the remote server.
|
||||
|
||||
## Configuration
|
||||
|
||||
The first few lines of the script are the config variables.
|
||||
Use them to set the remote host, destination folder, etc.
|
||||
|
||||
## Dependencies
|
||||
|
||||
This script will work on Xorg and Wayland by checking the `WAYLAND_DISPLAY` environment variable.
|
||||
|
||||
When used on Xorg, it requires `maim` for the image capture and `xsel` for clipboard management.
|
||||
When used on Wayland, it requires `grim`/`slurp` for the image capture and `wl-copy` for clipboard management.
|
||||
|
|
29
ppsh
29
ppsh
|
@ -39,18 +39,33 @@ exists() {
|
|||
}
|
||||
|
||||
main() {
|
||||
filename="$prefix$(generate_name $random_chars).png"
|
||||
date_folder="$(date "+$date_format")"
|
||||
local_directory="$local_root/$date_folder"
|
||||
mkdir -p "$local_directory"
|
||||
capture_and_upload "$local_directory/$filename" "$remote_directory/$filename"
|
||||
if [ -n "$1" ]; then
|
||||
ext="$(echo "$1" | awk '{ n=split($0, a, "."); print a[n] }')"
|
||||
if [ "$ext" == "$1" ]; then # file has no extension
|
||||
filename="$prefix$(generate_name $random_chars)"
|
||||
else
|
||||
filename="$prefix$(generate_name $random_chars).$ext"
|
||||
fi
|
||||
local_file="$1"
|
||||
else
|
||||
filename="$prefix$(generate_name $random_chars).png"
|
||||
date_folder="$(date "+$date_format")"
|
||||
local_directory="$local_root/$date_folder"
|
||||
mkdir -p "$local_directory"
|
||||
local_file="$local_directory/$filename"
|
||||
fi
|
||||
capture_and_upload "$local_file" "$remote_directory/$filename"
|
||||
}
|
||||
|
||||
capture_and_upload() {
|
||||
local_file="$1"
|
||||
remote_file="$2"
|
||||
if [ ! "$(exists "$remote_file")" ]; then
|
||||
capture "$local_file"
|
||||
# If the file already exists, we’re in file upload mode.
|
||||
# If it doesn’t, capture a screenshot and save it there.
|
||||
if [ ! -f "$local_file" ]; then
|
||||
capture "$local_file"
|
||||
fi
|
||||
upload "$local_file" "$remote_file"
|
||||
full_url="$url_template/$filename"
|
||||
clipboard "$full_url"
|
||||
|
@ -61,4 +76,4 @@ capture_and_upload() {
|
|||
fi
|
||||
}
|
||||
|
||||
main
|
||||
main "$1"
|
||||
|
|
Loading…
Reference in New Issue
Block a user