mirror of
https://github.com/mintycube/dotfiles.git
synced 2024-10-22 14:05:41 +02:00
add checks if local json is missing
This commit is contained in:
parent
ff95b12049
commit
563708819e
@ -4,25 +4,27 @@ json_url="https://raw.githubusercontent.com/ryanoasis/nerd-fonts/master/glyphnam
|
|||||||
local_file="$HOME/.local/share/script-data/chars/nerd-glyphs.json"
|
local_file="$HOME/.local/share/script-data/chars/nerd-glyphs.json"
|
||||||
|
|
||||||
function needs_update() {
|
function needs_update() {
|
||||||
local local_date
|
local local_date
|
||||||
local current_date
|
local current_date
|
||||||
local_date=$(stat -c %Y "$local_file" 2>/dev/null || echo 0)
|
local_date=$(stat -c %Y "$local_file" 2>/dev/null || echo 0)
|
||||||
current_date=$(date +%s)
|
current_date=$(date +%s)
|
||||||
[ "$((current_date - local_date))" -ge "$((14 * 24 * 3600))" ]
|
[ "$((current_date - local_date))" -ge "$((14 * 24 * 3600))" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
if needs_update; then
|
if [ ! -f "$local_file" ]; then
|
||||||
remote_date=$(curl -sI "$json_url" | grep -i '^Last-Modified:' | sed 's/Last-Modified: //')
|
curl -s "$json_url" -o "$local_file"
|
||||||
if [ "$remote_date" != "$(stat -c %y "$local_file" 2>/dev/null)" ]; then
|
elif needs_update; then
|
||||||
curl -s "$json_url" -o "$local_file"
|
remote_date=$(curl -sI "$json_url" | grep -i '^Last-Modified:' | sed 's/Last-Modified: //')
|
||||||
fi
|
if [ "$remote_date" != "$(stat -c %y "$local_file" 2>/dev/null)" ]; then
|
||||||
|
curl -s "$json_url" -o "$local_file"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
selected=$(jq -r '. as $input | to_entries[] | select(.key != "METADATA") | "\(.value.char) \(.key)"' "$local_file" | dmenu -bw 2 -i -W 290 -X 1061 -Y 15 -l 30 | sed "s/ .*//")
|
selected=$(jq -r '. as $input | to_entries[] | select(.key != "METADATA") | "\(.value.char) \(.key)"' "$local_file" | dmenu -bw 2 -i -W 290 -X 1061 -Y 15 -l 30 | sed "s/ .*//")
|
||||||
[ -z "$selected" ] && exit
|
[ -z "$selected" ] && exit
|
||||||
if [ -n "$1" ]; then
|
if [ -n "$1" ]; then
|
||||||
xdotool type "$selected"
|
xdotool type "$selected"
|
||||||
else
|
else
|
||||||
printf "%s" "$selected" | xclip -selection clipboard
|
printf "%s" "$selected" | xclip -selection clipboard
|
||||||
notify-send "$selected - copied to clipboard." &
|
notify-send "$selected - copied to clipboard." &
|
||||||
fi
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user