Compare commits
6 Commits
b2ea2c0bd9
...
469f1608d5
Author | SHA1 | Date |
---|---|---|
Michele Guerini Rocco | 469f1608d5 | |
Michele Guerini Rocco | c7b68ee90d | |
Michele Guerini Rocco | 8916cd5ad6 | |
Michele Guerini Rocco | 85bf0db0a3 | |
Michele Guerini Rocco | 97292aa847 | |
Michele Guerini Rocco | 0ff4809f6b |
|
@ -2,7 +2,7 @@
|
|||
|
||||
# set backlight brightness level
|
||||
|
||||
current=$(cat /sys/class/backlight/intel_backlight/brightness)
|
||||
current=$(cat /sys/class/backlight/acpi_video0/brightness)
|
||||
|
||||
if test -z "$1"; then
|
||||
echo "$current"
|
||||
|
@ -24,4 +24,4 @@ case "$1" in
|
|||
esac
|
||||
|
||||
echo "current: $new"
|
||||
echo "$new" > /sys/class/backlight/intel_backlight/brightness
|
||||
echo "$new" > /sys/class/backlight/acpi_video0/brightness
|
||||
|
|
|
@ -20,4 +20,4 @@ sed -i "s/theme=.*/theme=${theme:-dawn}/" "$XDG_CONFIG_HOME/nheko.conf"
|
|||
|
||||
xsetroot -fg "$(xrdb -get root.foreground)" \
|
||||
-bg "$(xrdb -get root.background)" \
|
||||
-bitmap ~/img/tiles/tile.xbm \
|
||||
-bitmap ~/img/tiles/arrows.xbm \
|
||||
|
|
|
@ -1,14 +1,19 @@
|
|||
#!/bin/sh
|
||||
|
||||
bin=$(env PATH="$(echo "$PATH" | sed "s|$(dirname "$0"):||g")" sh -c 'command -v qutebrowser')
|
||||
flags="--qt-flag ignore-gpu-blocklist
|
||||
--qt-flag enable-gpu-rasterization
|
||||
--qt-flag enable-native-gpu-memory-buffers
|
||||
--qt-flag num-raster-threads=4
|
||||
--qt-flag enable-oop-rasterization"
|
||||
|
||||
if pgrep qutebrowser >/dev/null; then
|
||||
exec "$bin" "$@"
|
||||
exec "$bin" $flags "$@"
|
||||
else
|
||||
url="$1"
|
||||
ver='1.6.3'
|
||||
proto=1
|
||||
sock="$XDG_RUNTIME_DIR/qutebrowser/ipc-$(printf "%s" "$USER" | md5sum | cut -d\ -f1)"
|
||||
fmt='{"args": ["%s"], "target_arg": null, "version": "%s", "protocol_version": %d, "cwd": "%s"}\n'
|
||||
printf "$fmt" "$url" "$ver" "$proto" "$PWD" | nc -U "$sock" 2>/dev/null || exec "$bin" "$@" &
|
||||
printf "$fmt" "$url" "$ver" "$proto" "$PWD" | nc -U "$sock" 2>/dev/null || exec "$bin" $flags "$@" &
|
||||
fi
|
||||
|
|
12
scripts/rec
12
scripts/rec
|
@ -1,18 +1,24 @@
|
|||
#!/bin/sh
|
||||
|
||||
record() {
|
||||
if test "$1" = "-s"; then
|
||||
geometry=$(hacksaw -f 'crop=%w:%h:%x:%y,scale_vaapi=%w:%h')
|
||||
else
|
||||
geometry='scale_vaapi=1920:1080'
|
||||
fi
|
||||
|
||||
sleep 2
|
||||
withcap sys_admin -- ffmpeg -f alsa -i recorder \
|
||||
-vaapi_device /dev/dri/renderD128 -f kmsgrab -i - -r 60 \
|
||||
-vf 'hwmap=derive_device=vaapi,scale_vaapi=w=1920:h=1080:format=nv12' \
|
||||
-c:v hevc_vaapi -qp 21 \
|
||||
-vf "hwmap=derive_device=vaapi,$geometry:format=nv12" \
|
||||
-c:v hevc_vaapi -qp 21 -rc_mode 1 \
|
||||
-c:a libopus -b:a 96k -ac 2 -ar 48000 \
|
||||
-y recording.mkv >/dev/null 2>&1
|
||||
}
|
||||
|
||||
if test ! -f recording.mkv; then
|
||||
echo recording in 2s...
|
||||
record &
|
||||
record "$@" &
|
||||
else
|
||||
pkill ffmpeg
|
||||
echo stopped recording
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
BEGIN {
|
||||
"nix build -f '<nixpkgs>' nmap --no-link --json | jq -r '.[0].outputs.out'"|getline nmap
|
||||
db = nmap"/share/nmap/nmap-mac-prefixes"
|
||||
while((getline line < db) > 0)
|
||||
{
|
||||
n = split(line, rec, " ");
|
||||
prefix = rec[1]
|
||||
vendors[prefix] = rec[2]
|
||||
for (i=3; i<n; i++)
|
||||
vendors[prefix] = vendors[prefix]" "rec[i]
|
||||
}
|
||||
FS=" |%"
|
||||
}
|
||||
|
||||
/ff:fe/ {
|
||||
eui64 = $4
|
||||
eui48 = eui64
|
||||
gsub(/ff:fe|fe80::/, "", eui48)
|
||||
gsub(":", "", eui48)
|
||||
mac = xor(strtonum("0x"eui48), lshift(1, 41))
|
||||
prefix = substr(sprintf("%X", mac), 0, 6)
|
||||
mac = sprintf("%012x", mac)
|
||||
prettymac = ""
|
||||
for (i=0; i<=6; i++)
|
||||
{ prettymac = prettymac substr(mac,2*i+1,2)
|
||||
if (i < 5) prettymac = prettymac":"
|
||||
}
|
||||
printf("%25s\t%s\t%s\n", eui64, prettymac, vendors[prefix])
|
||||
}
|
|
@ -0,0 +1,180 @@
|
|||
#!/bin/sh
|
||||
|
||||
print_usage() {
|
||||
cat <<EOF
|
||||
Usage: $(basename "$0") [OPTIONS] COMMAND [COMMAND_OPTIONS]
|
||||
|
||||
Get information about Trenitalia trains
|
||||
|
||||
Options:
|
||||
-h --help print this message
|
||||
|
||||
Commands:
|
||||
|
||||
search FROM TO [-i][--interactive] search for trains between two station
|
||||
-i --interactive allows selecting a train for more information
|
||||
|
||||
status TRAIN_ID [--board STATION] get realtime information about a train
|
||||
-b --board STATION prints the platform number when boarding
|
||||
then train from a given station
|
||||
EOF
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Prints realtime information about a train
|
||||
train_status() {
|
||||
train="$1"
|
||||
test "$2" = "--board" && board_station="$3"
|
||||
|
||||
# Resolve the station name, if necessary
|
||||
if test "${board_station%S}" = "$board_station"; then
|
||||
board_station=$(station_search "$board_station" | sed 's/^8300/S/g')
|
||||
fi
|
||||
|
||||
url='http://www.viaggiatreno.it/infomobilita/resteasy/viaggiatreno'
|
||||
today="$(date -d "$(date +%F)" +%s)000"
|
||||
station=$(curl -s "$url/cercaNumeroTrenoTrenoAutocomplete/$1" |
|
||||
grep "$today" | cut -d\| -f2 | cut -d- -f2)
|
||||
curl -s "$url/andamentoTreno/$station/$train/$today" | tee test.json |
|
||||
jq -r --arg board_station "$board_station" '
|
||||
# Functions to color text
|
||||
def red($x): "\u001B[1;31m\($x)\u001B[0m";
|
||||
def green($x): "\u001B[1;32m\($x)\u001B[0m";
|
||||
def yellow($x): "\u001B[1;36m\($x)\u001B[0m";
|
||||
|
||||
(if .tipoTreno == "PG" then green("regolare")
|
||||
elif .tipoTreno == "ST" then red("cancellato")
|
||||
elif .tipoTreno == "DV" then yellow("deviato")
|
||||
elif .tipoTreno == "PP" or
|
||||
.tipoTreno == "SI" or
|
||||
.tipoTreno == "SF" then yellow(.subTitle)
|
||||
else "sconosciuto"
|
||||
end) as $status
|
||||
| (if .nonPartito
|
||||
then []
|
||||
else ["ultima posizione: " + .stazioneUltimoRilevamento
|
||||
+ "(\(.compOraUltimoRilevamento))"]
|
||||
end) as $position
|
||||
| (if .ritardo <= 0
|
||||
then green(.compRitardo[0])
|
||||
else red(.compRitardo[0])
|
||||
end) as $late
|
||||
| (if $board_station
|
||||
then ["binario arrivo: " +
|
||||
(.fermate[] | select(.id == $board_station)
|
||||
| .binarioProgrammatoArrivoDescrizione)]
|
||||
else []
|
||||
end) as $platform
|
||||
| ["nome: \(.compNumeroTreno)",
|
||||
"stato: \($status)",
|
||||
"ritardo: \($late)"
|
||||
] + $platform + $position
|
||||
| join("\n")'
|
||||
}
|
||||
|
||||
|
||||
# Searches for a station by name and returns its ID
|
||||
station_search() {
|
||||
url='https://www.lefrecce.it/Channels.Website.BFF.WEB/website'
|
||||
# URL-encode the search string
|
||||
encoded=$(printf '%s' "$1" | jq -sRr '@uri')
|
||||
curl -s "$url/locations/search?name=$encoded&limit=1" | jq '.[0].id'
|
||||
}
|
||||
|
||||
|
||||
# Searches for a route between two stations
|
||||
route_search() {
|
||||
url='https://www.lefrecce.it/Channels.Website.BFF.WEB/website'
|
||||
query=$(cat <<EOF
|
||||
{
|
||||
"departureLocationId": "$1",
|
||||
"arrivalLocationId": "$2",
|
||||
"departureTime": "$(date --iso-8601=s)",
|
||||
"adults": 1,
|
||||
"children": 0,
|
||||
"criteria": {
|
||||
"frecceOnly": false,
|
||||
"regionalOnly": false,
|
||||
"noChanges": false,
|
||||
"order": "DEPARTURE_DATE",
|
||||
"limit": 6,
|
||||
"offset": 0
|
||||
},
|
||||
"advancedSearchRequest": { "bestFare": false }
|
||||
}
|
||||
EOF
|
||||
)
|
||||
|
||||
printf 'ora: \033[36m%s\033[0m\n\n' "$(date +%T)"
|
||||
curl -s --json "$query" "$url/ticket/solutions" |
|
||||
jq -r '
|
||||
"%FT%T.000+01:00" as $timefmt |
|
||||
|
||||
# Functions to color text
|
||||
def red($x): "\u001B[1;31m\($x)\u001B[0m";
|
||||
def green($x): "\u001B[1;32m\($x)\u001B[0m";
|
||||
def blue($x): "\u001B[1;34m\($x)\u001B[0m";
|
||||
|
||||
def time:
|
||||
# Extracts "HH:MM" from a timestamp
|
||||
strptime($timefmt) | mktime | strftime("%R");
|
||||
|
||||
def delta($stop; $start):
|
||||
# Computes the time elapsed between two dates
|
||||
[$stop, $start]
|
||||
| map(strptime($timefmt) | mktime) # seconds
|
||||
| .[0] - .[1]
|
||||
| ((./60) % 60) as $m
|
||||
| (./3600 | floor) as $h
|
||||
| (if $h > 0 then "\($h)h " else "" end) + "\($m)min";
|
||||
|
||||
def print_trip:
|
||||
# Prints a trip "station(time) → station(time)"
|
||||
(.duration // delta(.arrivalTime; .departureTime)) as $delta |
|
||||
"\(.origin)(\(green(.departureTime | time)))" +
|
||||
" → \(.destination)(\(.arrivalTime | time)) " +
|
||||
blue($delta);
|
||||
|
||||
def print_train:
|
||||
# Prints the train name and its trip
|
||||
"\(.train.description // .train.trainCategory): " + print_trip;
|
||||
|
||||
def print_summary:
|
||||
(.trains | length) as $ntrain |
|
||||
(if $ntrain > 2 then (", " + red("\($ntrain-1) cambi"))
|
||||
elif $ntrain == 2 then (", " + red("1 cambio"))
|
||||
else "" end) as $switch |
|
||||
"- " + print_trip + $switch + "\n "
|
||||
+ (.nodes | map(print_train) | join("\n "));
|
||||
|
||||
.solutions | map(.solution | print_summary) | join("\n\n")'
|
||||
}
|
||||
|
||||
handle_search() {
|
||||
# Get station IDs
|
||||
start_id=$(station_search "$1")
|
||||
stop_id=$(station_search "$2")
|
||||
|
||||
results=$(route_search "$start_id" "$stop_id")
|
||||
printf '%s' "$results"
|
||||
|
||||
if test "$3" = "-i" -o "$3" = "--interactive"; then
|
||||
# Ask user to select a train
|
||||
info=$(printf '%s' "$results" | fzf --ansi --no-sort --disabled | cut -d: -f1)
|
||||
# Print the train status
|
||||
train_id=$(printf '%s' "$info" | cut -d: -f1 | rev | cut -d' ' -f 1 | rev)
|
||||
# convert between different API conventions
|
||||
station_id=$(printf '%s' "$start_id" | sed 's/^8300/S/g')
|
||||
printf '\n\n'
|
||||
train_status "$train_id" --station "$station_id"
|
||||
fi
|
||||
}
|
||||
|
||||
test $# -eq 0 && print_usage
|
||||
|
||||
cmd="$1"; shift
|
||||
case "$cmd" in
|
||||
search) handle_search "$@" ;;
|
||||
status) train_status "$@" ;;
|
||||
*) print_usage
|
||||
esac
|
Loading…
Reference in New Issue