Add git-worked, and some cache-related shell funcs

This commit is contained in:
Sage Vaillancourt 2024-09-23 08:41:25 -04:00
parent b32cf97e95
commit d78e78be76
3 changed files with 85 additions and 0 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
git-mirror-machine/
.idea/ .idea/
*.swp *.swp
*.zip *.zip

View File

@ -1,6 +1,7 @@
#!/bin/bash #!/bin/bash
RUN_FIREFOX="MOZ_ENABLE_WAYLAND=1 setsid $HOME/.bin/firefox-developer-edition/firefox-bin" RUN_FIREFOX="MOZ_ENABLE_WAYLAND=1 setsid $HOME/.bin/firefox-developer-edition/firefox-bin"
echo "$RUN_FIREFOX"
kill $(pgrep firefox) kill $(pgrep firefox)
current_date="$(date '+%D')" current_date="$(date '+%D')"

View File

@ -10,6 +10,81 @@ fi
alias _slides="$(which slides 2> /dev/null || echo "echo 'slides not installed'")" alias _slides="$(which slides 2> /dev/null || echo "echo 'slides not installed'")"
CASCH_DIR="$HOME/.casch"
CASCH_MAP="$CASCH_DIR/.base-map.json"
function git-worked {
author="$1"
since="$2"
if [[ "$author" == "" ]]; then
author="Sage"
fi
if [[ "$since" == "" ]]; then
since="1 year ago"
fi
cd "$HOME/git"
local first=true
for l in $(find -maxdepth 1 -mindepth 1 -type d | grep -v ' '); do
cd ~/git
cd $l
if ! test -d .git; then
continue
fi
local LIST="$(git rev-list --oneline --author="$author" --since="$since" HEAD)"
if [[ "$(echo -E "$LIST" | wc -l)" > 1 ]]; then
if ! $first; then
echo
fi
first=false
echo -E $l
echo -E "$LIST"
fi
done
cd ~/git
}
function touch-cache {
local lastUpdate="$(date '+%s')"
mkdir -p "$CASCH_DIR"
test -f "$CASCH_MAP" || echo '{}' > "$CASCH_MAP"
jq --arg cachedCommand "$1" --arg filename "$2" --arg lastUpdate "$lastUpdate" '.+={($cachedCommand): {$filename, $lastUpdate}}' "$CASCH_MAP" > "$CASCH_DIR/.tempbase.json"
mv "$CASCH_DIR/.tempbase.json" "$CASCH_MAP"
}
function timer {
for i in {0..$(($1-1))}; do
echo $(($1-$i))
sleep 1
clear
done
cvlc --play-and-exit "$HOME/Downloads/bonk.ogg" &> /dev/null
}
function cache-is-older-than {
local currentTime="$(date '+%s')"
local lastUpdate="$(jq -r --arg cachedCommand "$1" '.[$cachedCommand].lastUpdate' "$CASCH_MAP")"
local olderThanSec="$2"
if [[ "$lastUpdate" == "null" ]]; then
return 0
fi
(($currentTime-$olderThanSec>$lastUpdate))
}
function cache-run {
local cacheFile="$CASCH_DIR/$@"
if cache-is-older-than "$@" 300; then
$@ | tee "$cacheFile"
touch-cache "$@" "$cacheFile"
else
cat "$cacheFile"
fi
}
alias cr='cache-run'
function roll { function roll {
local count=1 local count=1
if [[ "$2" != "" ]]; then if [[ "$2" != "" ]]; then
@ -191,6 +266,14 @@ alias tmux="tmux attach || tmux"
alias caddyfile="sudo vim /etc/caddy/Caddyfile" alias caddyfile="sudo vim /etc/caddy/Caddyfile"
alias cf="sudo vim /etc/caddy/Caddyfile" alias cf="sudo vim /etc/caddy/Caddyfile"
function v {
if test -f "$1"; then
vim "$1"
else
vim $1*
fi
}
function download-channel { function download-channel {
yt-dlp "$1" --format 'bestvideo[height=1080]+bestaudio/best' --download-archive archive.txt --output '%(uploader)s/%(upload_date)s.%(title)s.%(id)s.%(ext)s' --restrict-filenames --merge-output-format mkv --ignore-errors yt-dlp "$1" --format 'bestvideo[height=1080]+bestaudio/best' --download-archive archive.txt --output '%(uploader)s/%(upload_date)s.%(title)s.%(id)s.%(ext)s' --restrict-filenames --merge-output-format mkv --ignore-errors
} }