Add local file upload
This commit is contained in:
parent
bcb0e1212d
commit
d75236f43c
30
README.md
30
README.md
|
@ -1,5 +1,31 @@
|
||||||
# ppsh
|
# ppsh
|
||||||
A simple shell screenshot tool, named after the PPSh,
|
A simple shell screenshot tool that uploads to an ssh server,
|
||||||
a Soviet submachine gun, because it shoots and ends with `sh`.
|
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.
|
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() {
|
main() {
|
||||||
filename="$prefix$(generate_name $random_chars).png"
|
if [ -n "$1" ]; then
|
||||||
date_folder="$(date "+$date_format")"
|
ext="$(echo "$1" | awk '{ n=split($0, a, "."); print a[n] }')"
|
||||||
local_directory="$local_root/$date_folder"
|
if [ "$ext" == "$1" ]; then # file has no extension
|
||||||
mkdir -p "$local_directory"
|
filename="$prefix$(generate_name $random_chars)"
|
||||||
capture_and_upload "$local_directory/$filename" "$remote_directory/$filename"
|
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() {
|
capture_and_upload() {
|
||||||
local_file="$1"
|
local_file="$1"
|
||||||
remote_file="$2"
|
remote_file="$2"
|
||||||
if [ ! "$(exists "$remote_file")" ]; then
|
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"
|
upload "$local_file" "$remote_file"
|
||||||
full_url="$url_template/$filename"
|
full_url="$url_template/$filename"
|
||||||
clipboard "$full_url"
|
clipboard "$full_url"
|
||||||
|
@ -61,4 +76,4 @@ capture_and_upload() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
main
|
main "$1"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user