diff --git a/bin/job-run b/bin/job-run new file mode 100755 index 0000000..7171432 --- /dev/null +++ b/bin/job-run @@ -0,0 +1,18 @@ +#! /bin/bash + +# trap 'rm /tmp/running-jobs' SIGINT + +echo "$(date +%s) $1" > /tmp/running-jobs +sh -c "$1 > /tmp/jobs.log 2>&1" +STATUS=$? + +echo "$(date +%s) $1 $STATUS" > /tmp/finished-jobs +rm /tmp/running-jobs || true + +echo + +case $STATUS in + 0) notify-send "Job '$(basename ${1})' is done." ;; + *) notify-send "Job '$(basename ${1})' is failed." ;; +esac + diff --git a/bin/job-status b/bin/job-status new file mode 100755 index 0000000..4f6062a --- /dev/null +++ b/bin/job-status @@ -0,0 +1,36 @@ +#! /bin/bash + +OUTDATED_SEC=300 +RUNNING_LOG=/tmp/running-jobs +FINISHED_LOG=/tmp/finished-jobs + +now=$(date +%s) + +if test -f "$RUNNING_LOG"; then + CONTENT=$(cat $RUNNING_LOG) + TS=$(echo $CONTENT| awk '{print $1}') + JOB=$(echo $CONTENT| awk '{print $2}') + RUNNING_SEC=$(($now-$TS)) + JOB_NAME=$(basename $JOB) + echo "[RUNNING: ${RUNNING_SEC}s] ${JOB_NAME}" + exit 0; +fi + +if test -f "$FINISHED_LOG"; then + CONTENT=$(cat $FINISHED_LOG) + TS=$(echo $CONTENT| awk '{print $1}') + JOB=$(echo $CONTENT| awk '{print $2}') + STATUS=$(echo $CONTENT| awk '{print $3}') + + AGO_SEC=$(($now-$TS)) + JOB_NAME=$(basename $JOB) + + # print nothing if outdated + (( $OUTDATED_SEC<($now-$TS) )) && exit 0 + + case $STATUS in + 0) echo "[FINISHED: ${AGO_SEC}s ago] ${JOB_NAME}" ;; + *) echo "[FAILED: ${AGO_SEC}s] ${JOB_NAME}" ;; + esac + +fi diff --git a/bin/jobs/unsplash_dl.sh b/bin/jobs/unsplash_dl.sh new file mode 100755 index 0000000..c5ce547 --- /dev/null +++ b/bin/jobs/unsplash_dl.sh @@ -0,0 +1,12 @@ +#! /usr/bin/zsh +source ~/.zshrc + + +COLLECTION_ID=$(zenity --entry --title="Download Unsplash Collection" --text="Enter collection id:") + +if [ -z "${COLLECTION_ID}" ]; then + zenity --info --text="No collection id specified" + exit 1 +fi + +unsplash download -d ~/Pictures/Wallpapers --token $UNSPLASH_TOKEN -H --min-width 3840 --min-height 2160 -c "${COLLECTION_ID}" diff --git a/bin/wofi-jobs b/bin/wofi-jobs new file mode 100755 index 0000000..93636c1 --- /dev/null +++ b/bin/wofi-jobs @@ -0,0 +1,21 @@ +#!/usr/bin/env python3 + +import subprocess + +if __name__ == '__main__': + + + jobs = subprocess.run(['ls', '/home/anton/.bin/jobs'], encoding='utf-8', + capture_output=True).stdout.split('\n') + + title = 'wofi-jobs' + rofi_command = 'wofi -dmenu -i -p {}'.format(title) + rofi_input = '\n'.join(job for job in jobs) + cp = subprocess.run(rofi_command.split(), input=rofi_input, + encoding='utf-8', capture_output=True) + + if cp.returncode == 0: + file = cp.stdout.strip() + xdg_command = ["/home/anton/.bin/job-run", f"/home/anton/.bin/jobs/{file}"] + subprocess.run(xdg_command, + encoding='utf-8', capture_output=True)