add rofi calendar
This commit is contained in:
96
.config/rofi/scripts/calendar.sh
Executable file
96
.config/rofi/scripts/calendar.sh
Executable file
@@ -0,0 +1,96 @@
|
||||
#!/usr/bin/env bash
|
||||
DIR=$(dirname $PWD)
|
||||
|
||||
current_day=$(date +"%e")
|
||||
current_month=$(date +"%m")
|
||||
current_year=$(date +"%Y")
|
||||
|
||||
month=$(date +"%-m")
|
||||
year=$(date +"%Y")
|
||||
previous_month="◀"
|
||||
next_month="▶"
|
||||
last_selected_option=""
|
||||
|
||||
format_calendar () {
|
||||
echo "$1" \
|
||||
| sed -E 's/([[:alpha:]])__/\1\n/g' \
|
||||
| sed -E 's/___([[:digit:]])/.\n\1/g' \
|
||||
| sed -e 's/___/\n./g' \
|
||||
| sed -e 's/__/\n/g' \
|
||||
| sed -e 's/_/\n/g'
|
||||
}
|
||||
|
||||
print_month() {
|
||||
calendar="$(cal -v -- $1 $2 | tail -n +2 | sed -e 's/ /_/g')"
|
||||
echo "$(format_calendar "$calendar")"
|
||||
}
|
||||
|
||||
find_day_index() {
|
||||
index=0
|
||||
while IFS=' ' read -ra arr; do
|
||||
for i in "${arr[@]}"; do
|
||||
if [[ "$i" == "$2" ]]; then
|
||||
echo "$index"
|
||||
break
|
||||
fi
|
||||
((index++))
|
||||
done
|
||||
done <<< "$1"
|
||||
}
|
||||
|
||||
calendar_menu() {
|
||||
calendar_header=$(cal -v -- $month $year | head -n 1)
|
||||
|
||||
month_page="$(print_month $month $year)"
|
||||
calendar_body="\n\n\n$previous_month\n\n\n\n$month_page\n\n\n\n$next_month\n\n\n"
|
||||
|
||||
previous_month_index="3"
|
||||
next_month_index="59"
|
||||
calendar_body_column="7"
|
||||
urgent="-u $previous_month_index,$next_month_index"
|
||||
active=""
|
||||
selected_row=""
|
||||
|
||||
if [[ "$(echo $current_month | bc) $current_year" == "$(echo $month | bc) $year" ]]; then
|
||||
current_day_index=$(($(find_day_index "$month_page" $current_day) + $calendar_body_column))
|
||||
active="-a $current_day_index"
|
||||
selected_row="-selected-row $current_day_index"
|
||||
fi
|
||||
|
||||
if [[ $last_selected_option == $previous_month ]]; then
|
||||
selected_row="-selected-row $previous_month_index"
|
||||
fi
|
||||
|
||||
if [[ $last_selected_option == $next_month ]]; then
|
||||
selected_row="-selected-row $next_month_index"
|
||||
fi
|
||||
|
||||
echo -e "$calendar_body" | rofi -dmenu \
|
||||
-theme $HOME/.config/rofi/themes/calendar.rasi \
|
||||
-p "$calendar_header" $urgent $active $selected_row \
|
||||
-monitor -1
|
||||
}
|
||||
|
||||
while [[ true ]]; do
|
||||
selected=$(calendar_menu)
|
||||
last_selected_option="$selected"
|
||||
case $selected in
|
||||
$previous_month)
|
||||
((month--))
|
||||
if [[ $month -lt 1 ]]; then
|
||||
month=12
|
||||
((year--))
|
||||
fi
|
||||
;;
|
||||
$next_month)
|
||||
((month++))
|
||||
if [[ $month -gt 12 ]]; then
|
||||
month=1
|
||||
((year++))
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
break
|
||||
;;
|
||||
esac
|
||||
done
|
||||
38
.config/rofi/scripts/copyq.py
Executable file
38
.config/rofi/scripts/copyq.py
Executable file
@@ -0,0 +1,38 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import json
|
||||
import sys
|
||||
import subprocess as sp
|
||||
|
||||
copyq_script_getAll = r"""
|
||||
var result=[];
|
||||
for ( var i = 0; i < size(); ++i ) {
|
||||
var obj = {};
|
||||
obj.row = i;
|
||||
obj.mimetypes = str(read("?", i)).split("\n");
|
||||
obj.mimetypes.pop();
|
||||
obj.text = str(read(i));
|
||||
result.push(obj);
|
||||
}
|
||||
JSON.stringify(result);
|
||||
"""
|
||||
|
||||
if __name__ == '__main__':
|
||||
if (len(sys.argv) > 2):
|
||||
num = sys.argv[2].split(" - ")[0]
|
||||
sp.run(f'copyq select({num});'.split(),
|
||||
encoding='utf-8', stdout=sp.PIPE, stderr=sp.PIPE)
|
||||
else:
|
||||
p = sp.run('copyq -'.split(), input=copyq_script_getAll,
|
||||
encoding='utf-8', stdout=sp.PIPE, stderr=sp.PIPE)
|
||||
json_arr = json.loads(p.stdout)
|
||||
|
||||
num = 0
|
||||
items = []
|
||||
for json_obj in json_arr:
|
||||
text = json_obj['text']
|
||||
text = " ".join(filter(None, text.replace("\n", " ").split(" ")))
|
||||
items.append(str(num) + " - " + text)
|
||||
num += 1
|
||||
|
||||
print('\n'.join(x for x in items))
|
||||
Reference in New Issue
Block a user