From 6fae25b305d714b3ab7608fa003f1af9bf024545 Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Tue, 14 Feb 2023 13:33:23 +0800 Subject: Rename tools into bin --- bin/cron/task.cron | 2 + bin/csv/csv.2geojson | 46 ++++++++ bin/csv/csv.move_column | 18 +++ bin/csv/csv.reorder | 17 +++ bin/desktop/password-store.sh | 51 +++++++++ bin/desktop/takeshot | 78 +++++++++++++ bin/docker/dktags | 29 +++++ bin/gis/match-road.sh | 148 +++++++++++++++++++++++++ bin/git/check-repos.sh | 48 ++++++++ bin/git/swap-protocol.bash | 25 +++++ bin/github/github-release.sh | 154 ++++++++++++++++++++++++++ bin/gpx/footer | 1 + bin/gpx/gpx.check.py | 85 ++++++++++++++ bin/gpx/gpx.merge_gpx.sh | 5 + bin/gpx/gpx.merge_trk.sh | 4 + bin/gpx/gpx2geojson.sh | 48 ++++++++ bin/gpx/header | 10 ++ bin/init/check_upstream | 24 ++++ bin/init/exit.sh | 5 + bin/init/load-settings.sh | 70 ++++++++++++ bin/init/sync.sh | 37 +++++++ bin/install.sh | 30 +++++ bin/markdown/reveal | 45 ++++++++ bin/misc/brightness.sh | 10 ++ bin/misc/diff-highlight | 213 ++++++++++++++++++++++++++++++++++++ bin/misc/flash.sh | 39 +++++++ bin/misc/mvt_decode.py | 11 ++ bin/misc/ocr | 16 +++ bin/misc/refresh-todo.sh | 5 + bin/misc/simple_cors_server.py | 18 +++ bin/misc/sync-gist.sh | 21 ++++ bin/misc/transfer | 22 ++++ bin/osm/josm_install.sh | 8 ++ bin/osm/note | 1 + bin/osm/osm | 18 +++ bin/osm/osm.api.changeset.add | 10 ++ bin/osm/osm.api.changeset.close | 3 + bin/osm/osm.api.changeset.commit | 80 ++++++++++++++ bin/osm/osm.api.changeset.create | 25 +++++ bin/osm/osm.api.changeset.update | 9 ++ bin/osm/osm.api.changeset.upload | 6 + bin/osm/osm.api.fetch | 6 + bin/osm/osm.api.fetch.full | 5 + bin/osm/osm.api.fetch.history | 6 + bin/osm/osm.api.member.relation | 4 + bin/osm/osm.api.referenced.relation | 6 + bin/osm/osm.api.referenced.way | 5 + bin/osm/osm.api.upload.to | 12 ++ bin/osm/osm.file.get | 4 + bin/osm/osm.file.get.full | 4 + bin/osm/osm.file.query | 4 + bin/osm/osm.goto | 3 + bin/osm/osm.help | 33 ++++++ bin/osm/osm.list.ids | 3 + bin/osm/osm.list.tag | 10 ++ bin/osm/osm.list.tags | 15 +++ bin/osm/osm.member.relation | 8 ++ bin/osm/osm.osc.by_member | 31 ++++++ bin/osm/osm.osc.by_tag | 45 ++++++++ bin/osm/osm.osm.remove | 9 ++ bin/osm/osm.pbf.update | 41 +++++++ bin/osm/osm.query | 3 + bin/osm/sequence_number.sh | 22 ++++ bin/sns/mastodon.sh | 17 +++ bin/task/tkk | 7 ++ bin/unix/fdswap | 41 +++++++ bin/wiki/diary | 49 +++++++++ bin/wiki/log.sh | 31 ++++++ bin/wiki/notify | 7 ++ 69 files changed, 1926 insertions(+) create mode 100644 bin/cron/task.cron create mode 100755 bin/csv/csv.2geojson create mode 100755 bin/csv/csv.move_column create mode 100755 bin/csv/csv.reorder create mode 100755 bin/desktop/password-store.sh create mode 100755 bin/desktop/takeshot create mode 100755 bin/docker/dktags create mode 100755 bin/gis/match-road.sh create mode 100755 bin/git/check-repos.sh create mode 100755 bin/git/swap-protocol.bash create mode 100755 bin/github/github-release.sh create mode 100644 bin/gpx/footer create mode 100755 bin/gpx/gpx.check.py create mode 100755 bin/gpx/gpx.merge_gpx.sh create mode 100755 bin/gpx/gpx.merge_trk.sh create mode 100755 bin/gpx/gpx2geojson.sh create mode 100644 bin/gpx/header create mode 100755 bin/init/check_upstream create mode 100755 bin/init/exit.sh create mode 100755 bin/init/load-settings.sh create mode 100755 bin/init/sync.sh create mode 100755 bin/install.sh create mode 100755 bin/markdown/reveal create mode 100755 bin/misc/brightness.sh create mode 100755 bin/misc/diff-highlight create mode 100755 bin/misc/flash.sh create mode 100755 bin/misc/mvt_decode.py create mode 100755 bin/misc/ocr create mode 100755 bin/misc/refresh-todo.sh create mode 100755 bin/misc/simple_cors_server.py create mode 100755 bin/misc/sync-gist.sh create mode 100755 bin/misc/transfer create mode 100755 bin/osm/josm_install.sh create mode 100644 bin/osm/note create mode 100644 bin/osm/osm create mode 100755 bin/osm/osm.api.changeset.add create mode 100755 bin/osm/osm.api.changeset.close create mode 100755 bin/osm/osm.api.changeset.commit create mode 100755 bin/osm/osm.api.changeset.create create mode 100755 bin/osm/osm.api.changeset.update create mode 100755 bin/osm/osm.api.changeset.upload create mode 100755 bin/osm/osm.api.fetch create mode 100755 bin/osm/osm.api.fetch.full create mode 100755 bin/osm/osm.api.fetch.history create mode 100755 bin/osm/osm.api.member.relation create mode 100755 bin/osm/osm.api.referenced.relation create mode 100755 bin/osm/osm.api.referenced.way create mode 100755 bin/osm/osm.api.upload.to create mode 100755 bin/osm/osm.file.get create mode 100755 bin/osm/osm.file.get.full create mode 100755 bin/osm/osm.file.query create mode 100755 bin/osm/osm.goto create mode 100755 bin/osm/osm.help create mode 100755 bin/osm/osm.list.ids create mode 100755 bin/osm/osm.list.tag create mode 100755 bin/osm/osm.list.tags create mode 100755 bin/osm/osm.member.relation create mode 100755 bin/osm/osm.osc.by_member create mode 100755 bin/osm/osm.osc.by_tag create mode 100755 bin/osm/osm.osm.remove create mode 100755 bin/osm/osm.pbf.update create mode 100755 bin/osm/osm.query create mode 100755 bin/osm/sequence_number.sh create mode 100755 bin/sns/mastodon.sh create mode 100755 bin/task/tkk create mode 100755 bin/unix/fdswap create mode 100755 bin/wiki/diary create mode 100755 bin/wiki/log.sh create mode 100755 bin/wiki/notify (limited to 'bin') diff --git a/bin/cron/task.cron b/bin/cron/task.cron new file mode 100644 index 0000000..7521cca --- /dev/null +++ b/bin/cron/task.cron @@ -0,0 +1,2 @@ +# Push changes on ~/.task +*/20 * * * * cd ~/.task && git add * && git commit -am update && git push origin 2>&1 diff --git a/bin/csv/csv.2geojson b/bin/csv/csv.2geojson new file mode 100755 index 0000000..e742be6 --- /dev/null +++ b/bin/csv/csv.2geojson @@ -0,0 +1,46 @@ +#! /bin/bash + +# -s to skip specify columns of longitude and latitude +for i in "$@" +do +case $i in + -s) + lon_col=0; lat_col=1 + shift;; + + *) + csv=$i + shift;; +esac +done + +# if no -s option, just read from input +if [ "$lon_col" != "0" ]; then + # show each field with index in csv + echo -------------- > /dev/tty + head -1 < $csv | tr ',' '\n' | nl > /dev/tty + echo -------------- > /dev/tty + echo > /dev/tty + + # get index of lon/lat column + read -p "Number of longitude column: " lon_col + read -p "Number of latitude column: " lat_col +fi + +(which dos2unix &>/dev/null && dos2unix <$csv || cat $csv) |\ +# move lon and lat to the first and second column +awk -F',' -v lon_th=$lon_col -v lat_th=$lat_col '\ + BEGIN{OFS=","}\ + {printf $lon_th "," $lat_th; for (i=1; i<= NF; i++) if (i != lat_th && i != lon_th) printf "," $i; print ""}\ + ' |\ +# change csv into array format, like [lon, lat, "field1", field2...] +sed 's/[^,]*/"\0"/g; s/.*/[\0]/g' |\ +# wrap other fields as a json object, like [lon, lat, {...}] +jq -s '.[0][2:] as $fields | .[1:][] | [.[0], .[1], ([$fields, .[2:]] | transpose | map({(.[0]): .[1]}) | add)]' |\ +# create array of geojson point features +jq '{"type": "Feature", "properties": .[2], "geometry":{ "type": "Point", "coordinates": [(.[0] | tonumber), (.[1] | tonumber)] } }' |\ +# wrap features as geojson format +jq -s '{"type": "FeatureCollection", "features": .}' |\ +tee /tmp/geojson + +echo stored into /tmp/geojson > /dev/tty diff --git a/bin/csv/csv.move_column b/bin/csv/csv.move_column new file mode 100755 index 0000000..a62701f --- /dev/null +++ b/bin/csv/csv.move_column @@ -0,0 +1,18 @@ +#! /bin/bash + +# show each field with index in csv +echo -------------- > /dev/tty +head -1 < $1 | sed 's/,/ /g' | awk '{for (i=1; i<=NF; i++) printf $i "_" i " "; print ""}' > /dev/tty +echo -------------- > /dev/tty +echo > /dev/tty + +# get index of lon/lat column +read -p "Move which column? " origin_col +read -p "To which index? " new_col + +cat $1 | +# move lon and lat to the first and second column +awk -F',' -v OFS="," -v origin_th=$origin_col -v new_th=$new_col '\ + {for (i=1; i<= NF; i++) if (i == new_th) printf $origin_th OFS $i OFS; else if (i == origin_th); else printf $i OFS; print ""}\ + ' |\ +sed 's/,$//g' diff --git a/bin/csv/csv.reorder b/bin/csv/csv.reorder new file mode 100755 index 0000000..8a64239 --- /dev/null +++ b/bin/csv/csv.reorder @@ -0,0 +1,17 @@ +#! /bin/bash + +# show each field with index in csv +echo -------------- > /dev/tty +head -1 < $1 | awk -F',' '{for (i=1; i<=NF; i++) printf $i "_" i " "; print ""}' > /dev/tty +echo -------------- > /dev/tty +echo > /dev/tty + +read -p "type column numbers by new order, like 3 2 1: " order + +arrange=$(echo $order | sed -r 's/([^ ]+)/$\1/g' | tr ' ' ',') + +cat $1 |\ +awk -F',' "BEGIN{OFS=\",\"}{print $arrange}" |\ +tee /tmp/csv + +echo "Also copied to /tmp/csv" > /dev/tty diff --git a/bin/desktop/password-store.sh b/bin/desktop/password-store.sh new file mode 100755 index 0000000..1de3148 --- /dev/null +++ b/bin/desktop/password-store.sh @@ -0,0 +1,51 @@ +#! /bin/bash + +# Use rofi to quickly access password by command 'pass' +# xsel needed !! + +ROFI_ARGS=( "-font" "Hack 22" ) + +find ~/.password-store -name '*gpg' -printf %P\\n | \ +sed 's/.gpg$//' | \ +rofi -dmenu "${ROFI_ARGS[@]}" | { + # Get arguments for command 'pass' + read ARG1 ARG2 + + if [[ -z $ARG1 ]]; then + exit 1 + elif [[ $ARG1 == edit ]]; then + # Edit an existing password + alacritty --hold -e pass edit $ARG2 && \ + rofi -e Password Edited: $ARG2 + else + # If pass fails, then it means password doesn't exists + set pipefail + + pass $ARG1 | { + # If command fails, just fail directly + read PASSWORD; [[ -z $PASSWORD ]] && exit 1 + + # Simply copy password into system clipboard + echo $PASSWORD | xsel -ib + + # Show success message, and display extra contents + rofi "${ROFI_ARGS[@]}" \ + -e "Copied: $ARG1 $(echo; echo; cat | sed '1{/^$/d}')" + } || { + # Make sure user want to create a new password + return_code=$(alacritty -e sh -c ' + dialog --yesno "Password does not exist, Generate a new one?" 8 30; + echo "$?" + ') + [[ $return_code == 1 ]] && exit 1 + + # Generate a new password by ARG1 + alacritty -e pass generate $ARG1 --clip && \ + + # Show success message + rofi "${ROFI_ARGS[@]}" -e "Password Created and Copied: $ARG1" + } + + # TODO: if return code is 2, it means gpg password is not cached + fi +} diff --git a/bin/desktop/takeshot b/bin/desktop/takeshot new file mode 100755 index 0000000..09252f3 --- /dev/null +++ b/bin/desktop/takeshot @@ -0,0 +1,78 @@ +#!/usr/bin/env bash + +## Copyright (C) 2020-2022 Aditya Shakya +## Everyone is permitted to copy and distribute copies of this file under GNU-GPL3 + +## Script to take screenshots with maim + +time=`date +%Y-%m-%d-%H-%M-%S` +geometry=`xrandr | head -n1 | cut -d',' -f2 | tr -d '[:blank:],current'` +dir="`xdg-user-dir PICTURES`" +file="Screenshot_${time}_${geometry}.png" + +# notify and view screenshot +notify_view () { + dunstify -u low --replace=699 -i /usr/share/archcraft/icons/dunst/picture.png "Copied to clipboard." + viewnior ${dir}/"$file" + if [[ -e "$dir/$file" ]]; then + dunstify -u low --replace=699 -i /usr/share/archcraft/icons/dunst/picture.png "Screenshot Saved." + else + dunstify -u low --replace=699 -i /usr/share/archcraft/icons/dunst/picture.png "Screenshot Deleted." + fi +} + +# countdown +countdown () { + for sec in `seq $1 -1 1`; do + dunstify -t 1000 --replace=699 -i /usr/share/archcraft/icons/dunst/timer.png "Taking shot in : $sec" + sleep 1 + done +} + +# take shots +shotnow () { + cd ${dir} && maim -u -f png | tee "$file" | xclip -selection clipboard -t image/png + notify_view +} + +shot5 () { + countdown '5' + sleep 1 && cd ${dir} && maim -u -f png | tee "$file" | xclip -selection clipboard -t image/png + notify_view +} + +shot10 () { + countdown '10' + sleep 1 && cd ${dir} && maim -u -f png | tee "$file" | xclip -selection clipboard -t image/png + notify_view +} + +shotwin () { + cd ${dir} && maim -u -f png -i `xdotool getactivewindow` | tee "$file" | xclip -selection clipboard -t image/png + notify_view +} + +shotarea () { + cd ${dir} && maim -u -f png -s -b 2 -c 0.35,0.55,0.855 | tee "$file" | xclip -selection clipboard -t image/png + notify_view +} + +if [[ ! -d "$dir" ]]; then + mkdir -p "$dir" +fi + +if [[ "$1" == "--now" ]]; then + shotnow +elif [[ "$1" == "--in5" ]]; then + shot5 +elif [[ "$1" == "--in10" ]]; then + shot10 +elif [[ "$1" == "--win" ]]; then + shotwin +elif [[ "$1" == "--area" ]]; then + shotarea +else + echo -e "Available Options : --now --in5 --in10 --win --area" +fi + +exit 0 diff --git a/bin/docker/dktags b/bin/docker/dktags new file mode 100755 index 0000000..5a91434 --- /dev/null +++ b/bin/docker/dktags @@ -0,0 +1,29 @@ +#!/bin/bash + +# Orignally copied from https://stackoverflow.com/a/39454426/7051075 + +if [ $# -lt 1 ] +then +cat << HELP + +dktags -- list all tags for a Docker image on a remote registry. + +EXAMPLE: + - list all tags for ubuntu: + dktags ubuntu + + - list all php tags containing apache: + dktags php apache + +HELP +fi + +image="$1" +tags=`wget -q https://registry.hub.docker.com/v1/repositories/${image}/tags -O - | sed -e 's/[][]//g' -e 's/"//g' -e 's/ //g' | tr '}' '\n' | awk -F: '{print $3}'` + +if [ -n "$2" ] +then + tags=` echo "${tags}" | grep "$2" ` +fi + +echo "${tags}" diff --git a/bin/gis/match-road.sh b/bin/gis/match-road.sh new file mode 100755 index 0000000..d9beaae --- /dev/null +++ b/bin/gis/match-road.sh @@ -0,0 +1,148 @@ +#!/usr/bin/env bash +# +# Author: Pham +# +# This script accepts a single GPX file as parameter and +# output the processed GPX body to STDOUT, using Mapbox Map Matching API v4. +# read doc at: https://docs.mapbox.com/api/legacy/map-matching-v4/ +# +# Example: +# +# match-road.sh raw.gpx > new.gpx +# +# Hint: +# +# Remember to put Mapbox Access Token at the top! + +#set -x +set -e + +# put yout Mapbox token here +ACCESS_TOKEN=$(cat ~/settings/tokens/mapbox) +# number of coordinates for each Mapbox Map Matching API request, Maximum value is 100 +LIMIT=100 +# define the lowest confidence of accepted matched points +THRESHOLD=0.0001 + +if [[ -z $1 ]]; then echo "You need to give a gpx file!"; exit 1; fi +ORIGIN_DATA=/tmp/$(basename $1).origin +RESPONSES=/tmp/$(basename $1).responses && true > $RESPONSES +MATCHED=/tmp/$(basename $1).matched + +# extract data from the given gpx file +# only keep first point and remove the rest which in the same "second" +# input: [gpx format] +# output: [121.0179739,14.5515336] 1984-01-01T08:00:46 +get_data() { + sed -nr '// {H; /<\/trkpt>/ {x; s/\n/ /g; p; s/.*//; x}}' $1 | + sed -nr 'h; s/.*lon="([^"]+).*/\1/; H; g + s/.*lat="([^"]+).*/\1/; H; g + # If trkpt has no time, leave it blank + /time/ { + s/.*