Skip to content

Instantly share code, notes, and snippets.

@hdb
hdb / code-for-crontab.sh
Last active November 1, 2022 03:37
use VS code to edit crontabs
#!/bin/env bash
echo '#!/bin/env bash
OPTS=""
if [[ "$1" == /tmp/* ]]; then
OPTS="-w"
fi
"$(which code)" ${OPTS:-} -a "$@"
' > "$HOME/.local/bin/code-wait.sh"
@hdb
hdb / github-accnt-rename.sh
Created May 23, 2020 03:45
iteratively rename git remotes to new username
#! /usr/bin/env bash
oldusername="$1"
newusername="$2"
find . | grep -e .git$ | while read -r line; do
thedir="$(echo "$line" | sed -e 's|.git$||g')"
cd "$thedir"
oldorigin="$(git config --get remote.origin.url)"
if [[ "$oldorigin" == *"$oldusername"* ]]; then
@hdb
hdb / icloud-dl.sh
Created April 17, 2019 21:22
download and organize photos from icloud
#!/bin/bash
ICLOUD_UN="example@apple.com"
ICLOUD_PW="$(sudo script_to_retrive_pass)"
icloudpd ~/Pictures/ --folder-structure={:%m.%y} --username "$ICLOUD_UN" --password "ICLOUD_PW"
@hdb
hdb / ffhistory.sh
Created April 17, 2019 21:13
get firefox's most recently visited urls
#!/bin/bash
sqlite3 ~/.mozilla/firefox/$(ls ~/.mozilla/firefox/ | grep .default)/places.sqlite "select url from moz_places order by last_visit_date desc limit ${1-15}"
@hdb
hdb / bt-connect.sh
Created April 17, 2019 21:07
toggle connection to specified bluetooth device
#!/bin/bash
NAME="YOUR_DEVICE_NAME"
ADDRESS="YOUR_DEVICE_ADDRESS"
STR="$(echo "quit" | bluetoothctl | grep -oP '.*(?=#)' | tail -1)"
if [[ $STR == *"$NAME"* ]]; then
echo "disconnect $ADDRESS" | bluetoothctl | tail -3 | head -1
else
@hdb
hdb / word-diff2md.sh
Created April 17, 2019 20:58
get word-diff between two documents via pandoc convert
#!/bin/bash
OUT1=$(echo "$1" | sed -e 's|.*/||' | sed -e 's|\..*||')
OUT2=$(echo "$2" | sed -e 's|.*/||' | sed -e 's|\..*||')
if [ ! -d '/tmp/word-diff/' ]; then
mkdir '/tmp/word-diff/';
fi
FILE1="/tmp/word-diff/$OUT1.md"
@hdb
hdb / stillframe-video.sh
Created April 17, 2019 20:44
use ffmpeg to create video from audio and image
#!/bin/bash
ffmpeg -loop 1 -i $1 -i $2 -c:v libx264 -tune stillimage -c:a aac -b:a 192k -pix_fmt yuv420p -speed 10 -shortest $3
@hdb
hdb / convert2gif.sh
Created April 17, 2019 20:37
use ffmpeg to convert video to gif image format
#! /bin/bash
FILENAME=$(sed -e 's:.*/::' <<< "$1")
OUT=$(sed -e "s/\..*/\.gif/" <<< "$FILENAME")
FRAMERATE=${5-10}
PLAYRATE=$((45/$FRAMERATE))
@hdb
hdb / meld.sh
Created August 2, 2018 17:57
uses melt to concatenate randomly-chosen sequences from a video.
#!/bin/bash
: '
usage:
meld.sh [input file] [min] [max] [outlength] [fx] [mute] [output]
setup:
place meld.sh in path and install the melt command line tool from MLT. it may already be installed on your system if you use openshot or kdenlive or other programs which are powered by MLT, otherwise:
sudo install melt
@hdb
hdb / playrecentalbum.sh
Created July 23, 2018 19:05
find Nth most recent album and play from command line via mpv
#! /bin/bash
mpv "`find /path/to/music/library/ -maxdepth 2 -mindepth 2 -type d -printf '%T@ %p\n' | sort -n | tail -$1 | cut -f2- -d" " | head -1`" --no-video