Skip to content

Commit

Permalink
Add wofi jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
A committed Jun 8, 2024
1 parent f8dbed3 commit a8aa6d8
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 0 deletions.
18 changes: 18 additions & 0 deletions bin/job-run
Original file line number Diff line number Diff line change
@@ -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

36 changes: 36 additions & 0 deletions bin/job-status
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions bin/jobs/unsplash_dl.sh
Original file line number Diff line number Diff line change
@@ -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}"
21 changes: 21 additions & 0 deletions bin/wofi-jobs
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit a8aa6d8

Please sign in to comment.