From 14a5b74ed75dac51af724ca596425bb8c88d24b1 Mon Sep 17 00:00:00 2001 From: Fabian Weik Date: Fri, 16 Aug 2024 19:49:28 +0200 Subject: [PATCH 1/9] add option for autogenerated file name --- reSnap.sh | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/reSnap.sh b/reSnap.sh index 91d4d4d..4057e1a 100755 --- a/reSnap.sh +++ b/reSnap.sh @@ -10,7 +10,7 @@ fi # default values ip="${REMARKABLE_IP:-10.11.99.1}" -output_file="$tmp_dir/snapshot_$(date +%F_%H-%M-%S).png" +output_file="$tmp_dir/reSnap_$(date +%F_%H-%M-%S).png" delete_output_file="true" display_output_file="${RESNAP_DISPLAY:-true}" color_correction="${RESNAP_COLOR_CORRECTION:-true}" @@ -33,9 +33,14 @@ while [ $# -gt 0 ]; do shift ;; -o | --output) - output_file="$2" delete_output_file="false" - shift + if [ $# -gt 1 ] && ! [[ "$2" =~ "-" ]]; then + echo here + output_file="$2" + shift + else + output_file="" # empty means compute from notebook name + fi shift ;; -d | --display) @@ -76,6 +81,7 @@ while [ $# -gt 0 ]; do echo " $0 -l # snapshot in landscape" echo " $0 -s 192.168.2.104 # snapshot over wifi" echo " $0 -o snapshot.png # saves the snapshot in the current directory" + echo " $0 -o # same as above, but named after the notebook" echo " $0 -d # display the file" echo " $0 -n # don't display the file" echo " $0 -c # no color correction (reMarkable2)" From f0edf8b3dcfe73f0eac5c4842d9dd6059520babc Mon Sep 17 00:00:00 2001 From: Fabian Weik Date: Fri, 16 Aug 2024 21:00:37 +0200 Subject: [PATCH 2/9] check for next argument starting with - POSIX compliant --- README.md | 3 ++- reSnap.sh | 19 ++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 395e366..43f7937 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,8 @@ reMarkable screenshots over ssh. ### Options - `-s --source` You can specify a custom IP. If you want to use reSnap over the Wifi, specify the IP of your reMarkable here. -- `-o --output` You can specify a custom output file for reSnap. +- `-o --output` You can specify a custom output file for reSnap. [Future: If the argument is a directory, the file name is automatically generated from the notebook name] +- `-o` The output file name is automatically generated from the notebook name and placed in the current directory. - `-l --landscape` Snapshot has now the landscape orientation. - `-d --display` Force program to display the snapshot. (overwrites environment variable) - `-n --no-display` Force program to not display the snapshot. diff --git a/reSnap.sh b/reSnap.sh index 4057e1a..8745d55 100755 --- a/reSnap.sh +++ b/reSnap.sh @@ -34,14 +34,13 @@ while [ $# -gt 0 ]; do ;; -o | --output) delete_output_file="false" - if [ $# -gt 1 ] && ! [[ "$2" =~ "-" ]]; then - echo here - output_file="$2" + output_file="" # empty means compute from notebook name + shift + # if next argument is not empty and not an option (TODO: own function?) + if [ $# -gt 0 ] && [ $(expr "$1" : "-") -eq 0 ]; then + output_file="$1" shift - else - output_file="" # empty means compute from notebook name fi - shift ;; -d | --display) display_output_file="true" @@ -69,6 +68,7 @@ while [ $# -gt 0 ]; do ;; -i | --invert-colors) invert_colors="true" + shift ;; -v | --version) echo "$0 version $version" @@ -211,6 +211,10 @@ else decompress="tee" fi +if [ -z "$output_file" ]; then + output_file="test.png" +fi + # read and compress the data on the reMarkable # decompress and decode the data on this machine ssh_cmd "$head_fb0 | $compress" | @@ -236,9 +240,10 @@ fi if [ "$copy_to_clipboard" = "true" ]; then echo "Copying to clipboard" xclip -selection clipboard -t image/png -i "${output_file}" + # TODO: add support for wayland (wl-copy) fi +# Show the snapshot if [ "$display_output_file" = "true" ]; then - # show the snapshot feh --fullscreen "$output_file" fi From ebc35c8463f35d46122c06c9a34f8aab1b4b6c0b Mon Sep 17 00:00:00 2001 From: Fabian Weik Date: Fri, 16 Aug 2024 21:15:58 +0200 Subject: [PATCH 3/9] allow specifying an output path and automatic file name generation --- README.md | 4 ++-- reSnap.sh | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 43f7937..5614262 100644 --- a/README.md +++ b/README.md @@ -30,8 +30,8 @@ reMarkable screenshots over ssh. ### Options - `-s --source` You can specify a custom IP. If you want to use reSnap over the Wifi, specify the IP of your reMarkable here. -- `-o --output` You can specify a custom output file for reSnap. [Future: If the argument is a directory, the file name is automatically generated from the notebook name] -- `-o` The output file name is automatically generated from the notebook name and placed in the current directory. +- `-o --output` You can specify a custom output file for reSnap. If the argument is a directory, the file name is automatically generated from the notebook name. +- `-o` The current directory is used as the implicit argument of the option above. - `-l --landscape` Snapshot has now the landscape orientation. - `-d --display` Force program to display the snapshot. (overwrites environment variable) - `-n --no-display` Force program to not display the snapshot. diff --git a/reSnap.sh b/reSnap.sh index 8745d55..ca8dcef 100755 --- a/reSnap.sh +++ b/reSnap.sh @@ -10,7 +10,7 @@ fi # default values ip="${REMARKABLE_IP:-10.11.99.1}" -output_file="$tmp_dir/reSnap_$(date +%F_%H-%M-%S).png" +output_file="$tmp_dir" delete_output_file="true" display_output_file="${RESNAP_DISPLAY:-true}" color_correction="${RESNAP_COLOR_CORRECTION:-true}" @@ -34,7 +34,7 @@ while [ $# -gt 0 ]; do ;; -o | --output) delete_output_file="false" - output_file="" # empty means compute from notebook name + output_file="." shift # if next argument is not empty and not an option (TODO: own function?) if [ $# -gt 0 ] && [ $(expr "$1" : "-") -eq 0 ]; then @@ -211,8 +211,9 @@ else decompress="tee" fi -if [ -z "$output_file" ]; then - output_file="test.png" +if [ -d "$output_file" ]; then + output_file="${output_file}/test.png" + # reSnap_$(date +%F_%H-%M-%S).png fi # read and compress the data on the reMarkable From 07fd5ca4341954e31a12fb992b042f8af2aa1926 Mon Sep 17 00:00:00 2001 From: Fabian Weik Date: Fri, 16 Aug 2024 21:19:52 +0200 Subject: [PATCH 4/9] quote command to fix lint --- reSnap.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reSnap.sh b/reSnap.sh index ca8dcef..0fc4e3f 100755 --- a/reSnap.sh +++ b/reSnap.sh @@ -37,7 +37,7 @@ while [ $# -gt 0 ]; do output_file="." shift # if next argument is not empty and not an option (TODO: own function?) - if [ $# -gt 0 ] && [ $(expr "$1" : "-") -eq 0 ]; then + if [ $# -gt 0 ] && [ "$(expr "$1" : "-")" -eq 0 ]; then output_file="$1" shift fi From 0df396a59628e7f1f8ee4426c00f995cc6963827 Mon Sep 17 00:00:00 2001 From: Fabian Weik Date: Fri, 16 Aug 2024 21:37:59 +0200 Subject: [PATCH 5/9] wip get notebook name from tablet --- reSnap.sh | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/reSnap.sh b/reSnap.sh index 0fc4e3f..d0150d8 100755 --- a/reSnap.sh +++ b/reSnap.sh @@ -212,8 +212,18 @@ else fi if [ -d "$output_file" ]; then - output_file="${output_file}/test.png" - # reSnap_$(date +%F_%H-%M-%S).png + output_dir="$output_file" + + notebooks_dir="/home/root/.local/share/remarkable/xochitl" + notebook_data_file="$(ssh_cmd "ls -t $notebooks_dir" | head -n 1)" + notebook_uuid="$(basename $notebook_data_file | cut -d '.' -f 1)" + + notebook_metadata_file="$notebooks_dir/${notebook_uuid}.metadata" + metadata="$(ssh_cmd "$notebook_metadata_file")" + output_file_name="$(echo $metadata | jq)" + exit 1 + + output_file="${output_file}/${output_file_name} $(date +%F_%H-%M-%S).png" fi # read and compress the data on the reMarkable From c534a1099a9952d59d10114fda05d8ee1104ab35 Mon Sep 17 00:00:00 2001 From: Fabian Weik Date: Fri, 16 Aug 2024 21:46:13 +0200 Subject: [PATCH 6/9] fix output name generation --- reSnap.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/reSnap.sh b/reSnap.sh index d0150d8..c4bbb2b 100755 --- a/reSnap.sh +++ b/reSnap.sh @@ -219,11 +219,10 @@ if [ -d "$output_file" ]; then notebook_uuid="$(basename $notebook_data_file | cut -d '.' -f 1)" notebook_metadata_file="$notebooks_dir/${notebook_uuid}.metadata" - metadata="$(ssh_cmd "$notebook_metadata_file")" - output_file_name="$(echo $metadata | jq)" - exit 1 + metadata="$(ssh_cmd cat "$notebook_metadata_file")" + output_file_name="$(echo $metadata | jq -r '.visibleName')" - output_file="${output_file}/${output_file_name} $(date +%F_%H-%M-%S).png" + output_file="${output_file}/${output_file_name} [$(date "+%F %H:%M:%S")].png" fi # read and compress the data on the reMarkable From f366160b0367c4b4045d69f1cbc4cc03b326b6b5 Mon Sep 17 00:00:00 2001 From: Fabian Weik Date: Fri, 16 Aug 2024 21:48:36 +0200 Subject: [PATCH 7/9] fix lint --- README.md | 1 + reSnap.sh | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5614262..633b134 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ reMarkable screenshots over ssh. - The following programs are required on your computer: - `ffmpeg` - `feh` + - `jq` ## Usage diff --git a/reSnap.sh b/reSnap.sh index c4bbb2b..0aa1ea2 100755 --- a/reSnap.sh +++ b/reSnap.sh @@ -216,13 +216,14 @@ if [ -d "$output_file" ]; then notebooks_dir="/home/root/.local/share/remarkable/xochitl" notebook_data_file="$(ssh_cmd "ls -t $notebooks_dir" | head -n 1)" - notebook_uuid="$(basename $notebook_data_file | cut -d '.' -f 1)" + notebook_uuid="$(basename "$notebook_data_file" | cut -d '.' -f 1)" notebook_metadata_file="$notebooks_dir/${notebook_uuid}.metadata" metadata="$(ssh_cmd cat "$notebook_metadata_file")" - output_file_name="$(echo $metadata | jq -r '.visibleName')" + # TODO: if jq not installed, fallback + output_file_name="$(echo "$metadata" | jq -r '.visibleName')" - output_file="${output_file}/${output_file_name} [$(date "+%F %H:%M:%S")].png" + output_file="${output_dir}/${output_file_name} [$(date "+%F %H:%M:%S")].png" fi # read and compress the data on the reMarkable From 56bcd829fc5e4a4970fb0889bd97b7f7a1bba25d Mon Sep 17 00:00:00 2001 From: Fabian Weik Date: Tue, 20 Aug 2024 20:24:10 +0200 Subject: [PATCH 8/9] print out interesting info --- reSnap.sh | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/reSnap.sh b/reSnap.sh index 0aa1ea2..c8540e8 100755 --- a/reSnap.sh +++ b/reSnap.sh @@ -211,15 +211,19 @@ else decompress="tee" fi +# Get notebook metadata +notebooks_dir="/home/root/.local/share/remarkable/xochitl" +notebook_data_file="$(ssh_cmd "ls -u $notebooks_dir" | head -n 1)" +notebook_id="$(basename "$notebook_data_file" | cut -d '.' -f 1)" + +notebook_metadata_file="$notebooks_dir/${notebook_id}.metadata" +metadata="$(ssh_cmd cat "$notebook_metadata_file")" + +echo $metadata | jq "{ id: \"$notebook_id\", metadata: $metadata }" + if [ -d "$output_file" ]; then output_dir="$output_file" - notebooks_dir="/home/root/.local/share/remarkable/xochitl" - notebook_data_file="$(ssh_cmd "ls -t $notebooks_dir" | head -n 1)" - notebook_uuid="$(basename "$notebook_data_file" | cut -d '.' -f 1)" - - notebook_metadata_file="$notebooks_dir/${notebook_uuid}.metadata" - metadata="$(ssh_cmd cat "$notebook_metadata_file")" # TODO: if jq not installed, fallback output_file_name="$(echo "$metadata" | jq -r '.visibleName')" From dc49b03424a45243b909e3b8355962e032b20632 Mon Sep 17 00:00:00 2001 From: Fabian Weik Date: Tue, 20 Aug 2024 20:25:28 +0200 Subject: [PATCH 9/9] fix lint --- reSnap.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reSnap.sh b/reSnap.sh index c8540e8..7f68a9b 100755 --- a/reSnap.sh +++ b/reSnap.sh @@ -219,7 +219,7 @@ notebook_id="$(basename "$notebook_data_file" | cut -d '.' -f 1)" notebook_metadata_file="$notebooks_dir/${notebook_id}.metadata" metadata="$(ssh_cmd cat "$notebook_metadata_file")" -echo $metadata | jq "{ id: \"$notebook_id\", metadata: $metadata }" +echo "$metadata" | jq "{ id: \"$notebook_id\", metadata: $metadata }" if [ -d "$output_file" ]; then output_dir="$output_file"