mirror of https://tildegit.org/ben/dotfiles
import some sh scripts
parent
4d455c18ef
commit
70a8a6975a
|
@ -0,0 +1,18 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# covidate version 2024.01
|
||||||
|
# Copyright (C) 2024 anelki
|
||||||
|
#
|
||||||
|
# this is free software licensed under the anelki public license
|
||||||
|
#
|
||||||
|
# See the README and LICENSE files for further information.
|
||||||
|
#
|
||||||
|
# with thanks/apologies to jwz: https://www.jwz.org/blog/2020/08/the-date-is-now-tuesday-march-178th-2020/
|
||||||
|
# shows the date as the number of days since 2020-03-01
|
||||||
|
# and earlier version included 2020-03-11 in the calc (so 296 total days).
|
||||||
|
# corrected, as jwz pointed out: https://twitter.com/jwz/status/1366475255976398848
|
||||||
|
|
||||||
|
LC_TIME=C.UTF-8
|
||||||
|
echo -e "\n\a Today is...$(date +"%A"), March $(expr 1401 + $(date +"%j")), 2020 at $(date +"%T") \n Let's make it a \033[1m✨great✨\033[0m day! \n\n This year will be Different...in a good way I'm sure...\n"
|
||||||
|
exit 0
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
wp --path=/var/www/tcpinball.org post meta get $1 _publicize_shares --format=json \
|
||||||
|
| jq -r '[.[] | .message?]' \
|
||||||
|
| wp --path=/var/www/tcpinball.org post meta add $1 mf2_syndication --format=json
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
wp --path=/var/www/benharri.org post meta get $1 syndication_log --format=json \
|
||||||
|
| jq -r '[.[] | .data.url?]' \
|
||||||
|
| wp --path=/var/www/benharri.org post meta add $1 mf2_syndication --format=json
|
||||||
|
|
|
@ -0,0 +1,75 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# get players + names
|
||||||
|
playersjson=$(curl -s "https://app.matchplay.events/api/tournaments/$1?includePlayers=1" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-H "Accept: application/json")
|
||||||
|
|
||||||
|
# pull finals id from main tourney
|
||||||
|
finalsId=$(printf %s "$playersjson" | jq -r ".data.linkedTournamentId")
|
||||||
|
|
||||||
|
# get standings for finals
|
||||||
|
standingsids=$(curl -s "https://app.matchplay.events/api/tournaments/$finalsId/standings" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-H "Accept: application/json" \
|
||||||
|
| jq -r '.[] | .playerId')
|
||||||
|
|
||||||
|
# look up ifpa tourneys in TC for the date from matchplay
|
||||||
|
d=$(printf %s "$playersjson" | jq -r ".data.startUtc")
|
||||||
|
shortdate=$(date --date "$d" +"%B %-d")
|
||||||
|
ifpa=$(curl -s 'https://api.ifpapinball.com/v1/calendar/search?api_key=GET_YOUR_OWN&address=Traverse%20City&m=3')
|
||||||
|
ifpatourney=$(printf %s "$ifpa" | jq -r ".calendar[] | select(.start_date == \"$(date --date "$d" +"%F")\").tournament_id")
|
||||||
|
|
||||||
|
# set author, excerpt, and categories based on day-of-week
|
||||||
|
author=1
|
||||||
|
excerpt="Results for $shortdate tourney"
|
||||||
|
|
||||||
|
case $(date --date "$d" +"%a") in
|
||||||
|
Thu)
|
||||||
|
categories="58,54"
|
||||||
|
;;
|
||||||
|
Mon)
|
||||||
|
categories="58,52"
|
||||||
|
;;
|
||||||
|
Sun)
|
||||||
|
categories="58,51"
|
||||||
|
author=8
|
||||||
|
excerpt="Results for the $shortdate Belles tourney"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
categories="4"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# pull names from original tournament json by ids from standings
|
||||||
|
# gotta be a better way to do this
|
||||||
|
player1=$(printf %s "$playersjson" | jq -r ".data.players | .[] | select(.playerId == $(printf %s "$standingsids" | head -n1 | tail -n1)).name")
|
||||||
|
player2=$(printf %s "$playersjson" | jq -r ".data.players | .[] | select(.playerId == $(printf %s "$standingsids" | head -n2 | tail -n1)).name")
|
||||||
|
player3=$(printf %s "$playersjson" | jq -r ".data.players | .[] | select(.playerId == $(printf %s "$standingsids" | head -n3 | tail -n1)).name")
|
||||||
|
player4=$(printf %s "$playersjson" | jq -r ".data.players | .[] | select(.playerId == $(printf %s "$standingsids" | head -n4 | tail -n1)).name")
|
||||||
|
|
||||||
|
# create the post draft and save the id
|
||||||
|
postid=$(sudo -Hu www-data wp --path=/var/www/tcpinball.org \
|
||||||
|
post create \
|
||||||
|
--post_author="$author" \
|
||||||
|
--post_category="$categories" \
|
||||||
|
--post_title="$shortdate Results" \
|
||||||
|
--post_excerpt="$excerpt" \
|
||||||
|
--post_status=draft \
|
||||||
|
--porcelain \
|
||||||
|
--post_content="<!-- wp:paragraph -->
|
||||||
|
<p>Format: Group Match Play</p>
|
||||||
|
<!-- /wp:paragraph -->
|
||||||
|
|
||||||
|
<!-- wp:table {\"hasFixedLayout\":false} -->
|
||||||
|
<figure class=\"wp-block-table\"><table><thead><tr><th>Place</th><th>Player</th></tr></thead><tbody><tr><td>1st</td><td>$player1</td></tr><tr><td>2nd</td><td>$player2</td></tr><tr><td>3rd</td><td>$player3</td></tr><tr><td>4th</td><td>$player4</td></tr></tbody></table></figure>
|
||||||
|
<!-- /wp:table -->
|
||||||
|
|
||||||
|
<!-- wp:paragraph -->
|
||||||
|
<p>See the full results on <a href=\"https://app.matchplay.events/tournaments/$1\">Match Play</a> - <a href=\"https://app.matchplay.events/tournaments/$finalsId\">Finals</a> (<a href=\"https://www.ifpapinball.com/tournaments/view.php?t=$ifpatourney\">IFPA</a>).</p>
|
||||||
|
<!-- /wp:paragraph -->
|
||||||
|
")
|
||||||
|
|
||||||
|
# drop a link to the editor so i can attach the featured pic before publishing
|
||||||
|
printf "https://tcpinball.org/wp-admin/post.php?action=edit&post=%s\n" "$postid"
|
||||||
|
|
|
@ -1,161 +0,0 @@
|
||||||
# ____ ____
|
|
||||||
# / __/___ / __/
|
|
||||||
# / /_/_ / / /_
|
|
||||||
# / __/ / /_/ __/
|
|
||||||
# /_/ /___/_/ key-bindings.fish
|
|
||||||
#
|
|
||||||
# - $FZF_TMUX_OPTS
|
|
||||||
# - $FZF_CTRL_T_COMMAND
|
|
||||||
# - $FZF_CTRL_T_OPTS
|
|
||||||
# - $FZF_CTRL_R_OPTS
|
|
||||||
# - $FZF_ALT_C_COMMAND
|
|
||||||
# - $FZF_ALT_C_OPTS
|
|
||||||
|
|
||||||
# Key bindings
|
|
||||||
# ------------
|
|
||||||
function fzf_key_bindings
|
|
||||||
|
|
||||||
# Store current token in $dir as root for the 'find' command
|
|
||||||
function fzf-file-widget -d "List files and folders"
|
|
||||||
set -l commandline (__fzf_parse_commandline)
|
|
||||||
set -l dir $commandline[1]
|
|
||||||
set -l fzf_query $commandline[2]
|
|
||||||
|
|
||||||
# "-path \$dir'*/\\.*'" matches hidden files/folders inside $dir but not
|
|
||||||
# $dir itself, even if hidden.
|
|
||||||
test -n "$FZF_CTRL_T_COMMAND"; or set -l FZF_CTRL_T_COMMAND "
|
|
||||||
command find -L \$dir -mindepth 1 \\( -path \$dir'*/\\.*' -o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' \\) -prune \
|
|
||||||
-o -type f -print \
|
|
||||||
-o -type d -print \
|
|
||||||
-o -type l -print 2> /dev/null | sed 's@^\./@@'"
|
|
||||||
|
|
||||||
test -n "$FZF_TMUX_HEIGHT"; or set FZF_TMUX_HEIGHT 40%
|
|
||||||
begin
|
|
||||||
set -lx FZF_DEFAULT_OPTS "--height $FZF_TMUX_HEIGHT --reverse $FZF_DEFAULT_OPTS $FZF_CTRL_T_OPTS"
|
|
||||||
eval "$FZF_CTRL_T_COMMAND | "(__fzfcmd)' -m --query "'$fzf_query'"' | while read -l r; set result $result $r; end
|
|
||||||
end
|
|
||||||
if [ -z "$result" ]
|
|
||||||
commandline -f repaint
|
|
||||||
return
|
|
||||||
else
|
|
||||||
# Remove last token from commandline.
|
|
||||||
commandline -t ""
|
|
||||||
end
|
|
||||||
for i in $result
|
|
||||||
commandline -it -- (string escape $i)
|
|
||||||
commandline -it -- ' '
|
|
||||||
end
|
|
||||||
commandline -f repaint
|
|
||||||
end
|
|
||||||
|
|
||||||
function fzf-history-widget -d "Show command history"
|
|
||||||
test -n "$FZF_TMUX_HEIGHT"; or set FZF_TMUX_HEIGHT 40%
|
|
||||||
begin
|
|
||||||
set -lx FZF_DEFAULT_OPTS "--height $FZF_TMUX_HEIGHT $FZF_DEFAULT_OPTS --tiebreak=index --bind=ctrl-r:toggle-sort $FZF_CTRL_R_OPTS +m"
|
|
||||||
|
|
||||||
set -l FISH_MAJOR (echo $version | cut -f1 -d.)
|
|
||||||
set -l FISH_MINOR (echo $version | cut -f2 -d.)
|
|
||||||
|
|
||||||
# history's -z flag is needed for multi-line support.
|
|
||||||
# history's -z flag was added in fish 2.4.0, so don't use it for versions
|
|
||||||
# before 2.4.0.
|
|
||||||
if [ "$FISH_MAJOR" -gt 2 -o \( "$FISH_MAJOR" -eq 2 -a "$FISH_MINOR" -ge 4 \) ];
|
|
||||||
history -z | eval (__fzfcmd) --read0 --print0 -q '(commandline)' | read -lz result
|
|
||||||
and commandline -- $result
|
|
||||||
else
|
|
||||||
history | eval (__fzfcmd) -q '(commandline)' | read -l result
|
|
||||||
and commandline -- $result
|
|
||||||
end
|
|
||||||
end
|
|
||||||
commandline -f repaint
|
|
||||||
end
|
|
||||||
|
|
||||||
function fzf-cd-widget -d "Change directory"
|
|
||||||
set -l commandline (__fzf_parse_commandline)
|
|
||||||
set -l dir $commandline[1]
|
|
||||||
set -l fzf_query $commandline[2]
|
|
||||||
|
|
||||||
test -n "$FZF_ALT_C_COMMAND"; or set -l FZF_ALT_C_COMMAND "
|
|
||||||
command find -L \$dir -mindepth 1 \\( -path \$dir'*/\\.*' -o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' \\) -prune \
|
|
||||||
-o -type d -print 2> /dev/null | sed 's@^\./@@'"
|
|
||||||
test -n "$FZF_TMUX_HEIGHT"; or set FZF_TMUX_HEIGHT 40%
|
|
||||||
begin
|
|
||||||
set -lx FZF_DEFAULT_OPTS "--height $FZF_TMUX_HEIGHT --reverse $FZF_DEFAULT_OPTS $FZF_ALT_C_OPTS"
|
|
||||||
eval "$FZF_ALT_C_COMMAND | "(__fzfcmd)' +m --query "'$fzf_query'"' | read -l result
|
|
||||||
|
|
||||||
if [ -n "$result" ]
|
|
||||||
cd $result
|
|
||||||
|
|
||||||
# Remove last token from commandline.
|
|
||||||
commandline -t ""
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
commandline -f repaint
|
|
||||||
end
|
|
||||||
|
|
||||||
function __fzfcmd
|
|
||||||
test -n "$FZF_TMUX"; or set FZF_TMUX 0
|
|
||||||
test -n "$FZF_TMUX_HEIGHT"; or set FZF_TMUX_HEIGHT 40%
|
|
||||||
if [ -n "$FZF_TMUX_OPTS" ]
|
|
||||||
echo "fzf-tmux $FZF_TMUX_OPTS -- "
|
|
||||||
else if [ $FZF_TMUX -eq 1 ]
|
|
||||||
echo "fzf-tmux -d$FZF_TMUX_HEIGHT -- "
|
|
||||||
else
|
|
||||||
echo "fzf"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
bind \ct fzf-file-widget
|
|
||||||
bind \cr fzf-history-widget
|
|
||||||
bind \ec fzf-cd-widget
|
|
||||||
|
|
||||||
if bind -M insert > /dev/null 2>&1
|
|
||||||
bind -M insert \ct fzf-file-widget
|
|
||||||
bind -M insert \cr fzf-history-widget
|
|
||||||
bind -M insert \ec fzf-cd-widget
|
|
||||||
end
|
|
||||||
|
|
||||||
function __fzf_parse_commandline -d 'Parse the current command line token and return split of existing filepath and rest of token'
|
|
||||||
# eval is used to do shell expansion on paths
|
|
||||||
set -l commandline (eval "printf '%s' "(commandline -t))
|
|
||||||
|
|
||||||
if [ -z $commandline ]
|
|
||||||
# Default to current directory with no --query
|
|
||||||
set dir '.'
|
|
||||||
set fzf_query ''
|
|
||||||
else
|
|
||||||
set dir (__fzf_get_dir $commandline)
|
|
||||||
|
|
||||||
if [ "$dir" = "." -a (string sub -l 1 -- $commandline) != '.' ]
|
|
||||||
# if $dir is "." but commandline is not a relative path, this means no file path found
|
|
||||||
set fzf_query $commandline
|
|
||||||
else
|
|
||||||
# Also remove trailing slash after dir, to "split" input properly
|
|
||||||
set fzf_query (string replace -r "^$dir/?" -- '' "$commandline")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
echo $dir
|
|
||||||
echo $fzf_query
|
|
||||||
end
|
|
||||||
|
|
||||||
function __fzf_get_dir -d 'Find the longest existing filepath from input string'
|
|
||||||
set dir $argv
|
|
||||||
|
|
||||||
# Strip all trailing slashes. Ignore if $dir is root dir (/)
|
|
||||||
if [ (string length -- $dir) -gt 1 ]
|
|
||||||
set dir (string replace -r '/*$' -- '' $dir)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Iteratively check if dir exists and strip tail end of path
|
|
||||||
while [ ! -d "$dir" ]
|
|
||||||
# If path is absolute, this can keep going until ends up at /
|
|
||||||
# If path is relative, this can keep going until entire input is consumed, dirname returns "."
|
|
||||||
set dir (dirname -- "$dir")
|
|
||||||
end
|
|
||||||
|
|
||||||
echo $dir
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
|
@ -1,6 +0,0 @@
|
||||||
function git_branch
|
|
||||||
if is_git
|
|
||||||
echo (git rev-parse --abbrev-ref HEAD ^/dev/null)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
function is_git
|
|
||||||
git rev-parse --verify HEAD >/dev/null 2>&1
|
|
||||||
end
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
function is_git_ahead
|
|
||||||
set -l revs (git rev-list origin/(git_branch)..HEAD ^/dev/null)
|
|
||||||
[ "$revs" != "" ]
|
|
||||||
end
|
|
||||||
|
|
|
@ -1,13 +0,0 @@
|
||||||
function is_git_dirty
|
|
||||||
# based on https://github.com/git/git/blob/master/git-sh-setup.sh#L210
|
|
||||||
|
|
||||||
is_git; or return 1
|
|
||||||
|
|
||||||
if git diff-files --quiet --ignore-submodules; and git diff-index --cached --quiet --ignore-submodules HEAD --
|
|
||||||
return 1
|
|
||||||
else
|
|
||||||
# we're dirty
|
|
||||||
return 0
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
function ls
|
|
||||||
command ls --color=auto $argv
|
|
||||||
end
|
|
||||||
|
|
|
@ -1,7 +0,0 @@
|
||||||
function vz
|
|
||||||
set file (fzf --height 40% --reverse)
|
|
||||||
if test -f $file
|
|
||||||
vim $file
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
Loading…
Reference in New Issue