aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2019-04-28 13:18:49 +0000
committerEuAndreh <eu@euandre.org>2019-04-28 13:18:49 +0000
commit4a73dca595e57751448899053cddb958c17fe75c (patch)
tree8c1a0b9d997fc4a0531559f6b7e8102deae25f74 /scripts
parentUpdate os-installation.sh (diff)
parentSplit vagrant cmds. (diff)
downloaddotfiles-4a73dca595e57751448899053cddb958c17fe75c.tar.gz
dotfiles-4a73dca595e57751448899053cddb958c17fe75c.tar.xz
Merge remote-tracking branch 'srht/master'
Diffstat (limited to 'scripts')
-rw-r--r--scripts/atom.js22
-rwxr-xr-xscripts/atom.sh30
-rwxr-xr-xscripts/autotime76
-rwxr-xr-xscripts/backup.sh14
-rwxr-xr-xscripts/buku-add.sh3
-rwxr-xr-xscripts/buku-archive.sh31
-rwxr-xr-xscripts/buku-delete.sh30
-rwxr-xr-xscripts/bump.sh21
-rwxr-xr-xscripts/cp-todos.sh4
-rwxr-xr-xscripts/gc.sh27
-rwxr-xr-xscripts/git-blame-someone-else21
-rwxr-xr-xscripts/mail.sh2
-rwxr-xr-xscripts/once-only-nextcloud.sh9
-rwxr-xr-xscripts/once-only-owncloud.sh9
-rwxr-xr-xscripts/single-monitor.sh2
-rwxr-xr-xscripts/sl13
-rwxr-xr-xscripts/sleepsort20
-rwxr-xr-x[-rw-r--r--]scripts/startx2
-rwxr-xr-xscripts/three-monitors.sh2
19 files changed, 155 insertions, 183 deletions
diff --git a/scripts/atom.js b/scripts/atom.js
new file mode 100644
index 0000000..878df05
--- /dev/null
+++ b/scripts/atom.js
@@ -0,0 +1,22 @@
+const RSS = require('rss');
+
+const feedName = process.argv[2];
+const feedSrc = process.argv[3];
+
+const feed = new RSS({
+ title: `Buku feed tag for '${feedName}'.`,
+ description: `Buku feed tag for ${feedName}`,
+});
+
+const items = require(feedSrc);
+items.forEach(({ title, description, uri }) => {
+ feed.item({
+ title,
+ description,
+ url: uri
+ });
+});
+
+const xml = feed.xml({indent: true});
+
+console.log(xml);
diff --git a/scripts/atom.sh b/scripts/atom.sh
new file mode 100755
index 0000000..6ca4110
--- /dev/null
+++ b/scripts/atom.sh
@@ -0,0 +1,30 @@
+#!/usr/bin/env bash
+set -euo pipefail
+cd "$(dirname "${BASH_SOURCE[0]}")"
+
+if [[ ! -d "node_modules" ]]; then
+ npm i rss
+fi
+
+RSS_DIR="$HOME/.newsboat"
+LINKS_OUT="$RSS_DIR/gen/buku.urls"
+
+mkdir -p "$RSS_DIR/gen"
+
+# Empty the text file
+true > "$LINKS_OUT"
+
+feed() {
+ local tag="$1"
+ local tmp="/tmp/$tag.json"
+ buku -t "$tag" --json > "$tmp"
+ if [[ -s "$tmp" ]]; then
+ node atom.js "$tag" "$tmp" > "$RSS_DIR/gen/$1.xml"
+ echo "file://$RSS_DIR/gen/$1.xml" >> "$LINKS_OUT"
+ fi
+}
+
+feed ril
+feed simple-archive
+
+cat "$DOTFILES/newsboat/urls" <(echo) "$LINKS_OUT" > "$RSS_DIR/urls"
diff --git a/scripts/autotime b/scripts/autotime
deleted file mode 100755
index fb01392..0000000
--- a/scripts/autotime
+++ /dev/null
@@ -1,76 +0,0 @@
-#!/usr/bin/env perl6
-
-# FIXME: stdin support with lines()
-# FIXME: --help and -h support
-
-sub from-timestamp(Int \timestamp) {
- sub formatter($_) {
- sprintf '%04d-%02d-%02d %02d:%02d:%02d',
- .year, .month, .day,
- .hour, .minute, .second,
- }
- given DateTime.new(+timestamp, :&formatter) {
- when .Date.DateTime == $_ { return .Date }
- default { return $_ }
- }
-}
-
-sub from-date-string(Str $date, Str $time?) {
- my $d = Date.new($date);
- if $time {
- my ( $hour, $minute, $second ) = $time.split(':');
- return DateTime.new(date => $d, :$hour, :$minute, :$second);
- } else {
- return $d.DateTime;
- }
-}
-
-# FIXME: add test
-multi sub convert(Int \timestamp) {
- from-timestamp(+timestamp);
-}
-
-# FIXME: add test
-multi sub convert(Str $date where { try Date.new($_) }, Str $time?) {
- from-date-string($date, $time).posix;
-}
-
-# FIXME: add test
-#| Convert timestamp to ISO date
-multi sub MAIN(Int \timestamp) {
- say convert(+timestamp);
-}
-
-# FIXME: add test
-#| Convert ISO date to timestamp
-multi sub MAIN(Str $date where { try Date.new($_) }, Str $time?) {
- say convert($date, $time);
-}
-
-# multi sub MAIN() {
-# for lines() -> $line {
-
-# }
-# }
-
-#| Run internal tests
-multi sub MAIN('test') is hidden-from-USAGE {
- use Test;
- plan 2;
- subtest 'timestamp', {
- plan 2;
- is-deeply from-timestamp(1450915200), Date.new('2015-12-24'),
- 'Date';;
- my $dt = from-timestamp(1450915201);
- is $dt, "2015-12-24 00:00:01",
- 'DateTime with string formatting';
- };
- subtest 'from-date-string', {
- plan 2;
- is from-date-string('2015-12-24').posix, 1450915200,
- 'one argument';
- is from-date-string('2015-12-24', '00:00:01').posix,
- 1450915201,
- 'two arguments';
- };
-}
diff --git a/scripts/backup.sh b/scripts/backup.sh
index a33a630..f31a503 100755
--- a/scripts/backup.sh
+++ b/scripts/backup.sh
@@ -6,12 +6,12 @@
#
if [ ! -d ~/UTCLOUD/ ]; then
- red "~/UTCLOUD not attached. Backup not started."
+ red "$HOME/UTCLOUD not attached. Backup not started."
exit 1
fi
if [ ! -d ~/borgbackup/ ]; then
- yellow "~/borgbackup/ repository doesn't exist. Downloading latest version from ~/UTCLOUD/borg/borgbackup/ into ~/borgbackup/"
+ yellow "$HOME/borgbackup/ repository doesn't exist. Downloading latest version from ~/UTCLOUD/borg/borgbackup/ into ~/borgbackup/"
# The initial borg repo was created with:
# $ borg init --append-only --encryption=keyfile ~/borgbackup
# See also: https://borgbackup.readthedocs.io/en/stable/usage/notes.html#append-only-mode
@@ -27,7 +27,7 @@ borg create \
--progress \
--compression lzma,6 \
~/borgbackup::"{hostname}-{now}-${BACKUP_TAG}" \
- ~/Nextcloud/ \
+ ~/ownCloud/ \
~/mbsync/
# add folders to be backed up here
green "Done"
@@ -46,7 +46,7 @@ green "Done"
#
yellow "Backing up git repos"
-pushd ~/
+pushd ~/ || exit 1
mr -s master
mr -s status
@@ -54,13 +54,13 @@ mr -s -j16 update
mr -s hd
mr -s -j4 rsyncnet
-popd
+popd || exit 1
yellow "Syncing annex"
-pushd ~/annex/
+pushd ~/annex/ || exit 1
git annex sync
-popd
+popd || exit 1
green "Done"
diff --git a/scripts/buku-add.sh b/scripts/buku-add.sh
new file mode 100755
index 0000000..005adbd
--- /dev/null
+++ b/scripts/buku-add.sh
@@ -0,0 +1,3 @@
+#!/usr/bin/env bash
+
+xclip -o | xargs -I{} buku -a "{}" ril
diff --git a/scripts/buku-archive.sh b/scripts/buku-archive.sh
new file mode 100755
index 0000000..2a2a702
--- /dev/null
+++ b/scripts/buku-archive.sh
@@ -0,0 +1,31 @@
+#!/usr/bin/env bash
+
+SEL="$(xclip -o | tr -d '\n')"
+if [[ -z "${SEL// }" ]]; then
+ echo "Empty selection."
+ exit 1
+fi
+BOOKMARK_ID=
+IFS="
+"
+BOOKMARKS="$(buku "$SEL" -f 1 --tacit)"
+
+for bookmark in $BOOKMARKS; do
+ echo "$bookmark"
+ ID="$(echo "$bookmark" | cut -d$'\t' -f 1)"
+ URL="$(echo "$bookmark" | cut -d$'\t' -f 2)"
+ if [[ "$URL" = "$SEL" ]]; then
+ BOOKMARK_ID="$ID"
+ break
+ fi
+done
+
+
+if [[ -n "$BOOKMARK_ID" ]]; then
+ echo "Archiving $BOOKMARK_ID (URL: $SEL)."
+ buku -u "$BOOKMARK_ID" --tag - ril
+ buku -u "$BOOKMARK_ID" --tag + simple-archive
+else
+ echo "Bookmark for '$SEL' not found."
+ exit 1
+fi
diff --git a/scripts/buku-delete.sh b/scripts/buku-delete.sh
new file mode 100755
index 0000000..01de451
--- /dev/null
+++ b/scripts/buku-delete.sh
@@ -0,0 +1,30 @@
+#!/usr/bin/env bash
+
+SEL="$(xclip -o | tr -d '\n')"
+if [[ -z "${SEL// }" ]]; then
+ echo "Empty selection."
+ exit 1
+fi
+BOOKMARK_ID=
+IFS="
+"
+BOOKMARKS="$(buku "$SEL" -f 1 --tacit)"
+
+for bookmark in $BOOKMARKS; do
+ echo "$bookmark"
+ ID="$(echo "$bookmark" | cut -d$'\t' -f 1)"
+ URL="$(echo "$bookmark" | cut -d$'\t' -f 2)"
+ if [[ "$URL" = "$SEL" ]]; then
+ BOOKMARK_ID="$ID"
+ break
+ fi
+done
+
+
+if [[ -n "$BOOKMARK_ID" ]]; then
+ echo "Deleting $BOOKMARK_ID (URL: $SEL)."
+ buku -d "$BOOKMARK_ID" --tacit
+else
+ echo "Bookmark for '$SEL' not found."
+ exit 1
+fi
diff --git a/scripts/bump.sh b/scripts/bump.sh
deleted file mode 100755
index 86eed54..0000000
--- a/scripts/bump.sh
+++ /dev/null
@@ -1,21 +0,0 @@
-#!/usr/bin/env bash
-
-function latest_version() {
- git tag | sort -V | tail -n 1
-}
-
-function overflow_bump() {
- IFS=".$IFS"
- read a b c
- if [[ "$b" == 999 ]]; then
- echo $((a + 1)).0.0
- elif [[ "$c" == 999 ]]; then
- echo $a.$((b + 1)).0
- else
- echo $a.$b.$((c + 1))
- fi
-}
-
-latest_version | overflow_bump
-
-echo "$1" | overflow_bump
diff --git a/scripts/cp-todos.sh b/scripts/cp-todos.sh
new file mode 100755
index 0000000..e839ae8
--- /dev/null
+++ b/scripts/cp-todos.sh
@@ -0,0 +1,4 @@
+#!/usr/bin/env bash
+
+cp "$HOME/annex/txt/TODOs.org" "$HOME/ownCloud/Notes/org.txt"
+cp "$HOME/annex/txt/TODOs.org" "$HOME/ownCloud/cache/TODOs.org"
diff --git a/scripts/gc.sh b/scripts/gc.sh
index 9670149..c93c948 100755
--- a/scripts/gc.sh
+++ b/scripts/gc.sh
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
disk_space() {
- ,u | awk '{print $5" "$6}'
+ u | awk '{print $5" "$6}'
}
before=$(disk_space)
@@ -10,8 +10,8 @@ yellow "Cleaning up the NixOS store"
profiles=(per-user/root/channels per-user/andreh/profile per-user/andreh/channels system)
-for p in ${profiles[@]}; do
- sudo nix-env --delete-generations old -p /nix/var/nix/profiles/$p
+for p in "${profiles[@]}"; do
+ sudo nix-env --delete-generations old -p "/nix/var/nix/profiles/$p"
done
# Current profile, change when installing with =nix-env -iA nixpkgs.bsdgames=
@@ -28,7 +28,7 @@ guix gc
yellow "Cleaning up up the Trash and /tmp folders"
-rm -rf ~/.local/share/Trash/files/*
+sudo rm -rf ~/.local/share/Trash/files/*
# https://askubuntu.com/a/609396
sudo find /tmp -type f -atime +10 -delete
@@ -36,23 +36,24 @@ sudo find /tmp -type f -atime +10 -delete
yellow "Erasing docker images"
echo y | docker system prune -a
-docker rmi $(docker images -a -q)
-docker rm $(docker ps -a -f status=exited -q)
+docker rmi "$(docker images -a -q)"
+docker rm "$(docker ps -a -f status=exited -q)"
-docker stop $(docker ps -a -q)
-docker rm $(docker ps -a -q)
+docker stop "$(docker ps -a -q)"
+docker rm "$(docker ps -a -q)"
echo y | docker volume prune
echo y | docker container prune
+
+# Source: https://www.reddit.com/r/emacs/comments/6wqfp3/notmuch_delete_mail/
+yellow "Clean up deleted email files"
+notmuch search --output=files --exclude=false tag:deleted | xargs -I{} rm "{}"
+notmuch new
+
after=$(disk_space)
green "Done."
green "Disk space before and after:"
blue " before: ${before}"
blue " after: ${after}"
-
-# Clean up deleted email files:
-# Source: https://www.reddit.com/r/emacs/comments/6wqfp3/notmuch_delete_mail/
-# notmuch search --output=files --exclude=false tag:deleted | xargs -I{} rm "{}"
-# notmuch new
diff --git a/scripts/git-blame-someone-else b/scripts/git-blame-someone-else
deleted file mode 100755
index dd71826..0000000
--- a/scripts/git-blame-someone-else
+++ /dev/null
@@ -1,21 +0,0 @@
-#!/usr/bin/env bash
-
-# Taken from https://github.com/jayphelps/git-blame-someone-else/
-
-if [ $# -ne 2 ]; then
- >&2 echo "Usage: $0 <author> <commit>"
- exit 1
-fi
-
-AUTHOR=$1
-AUTHOR_NAME=$(echo $AUTHOR | perl -wlne '/^(.*?)\s*<.*>$/ and print $1')
-AUTHOR_EMAIL=$(echo $AUTHOR | perl -wlne '/^.*\s*<(.*)>$/ and print $1')
-COMMIT=$(git rev-parse --short $2)
-
-{
- GIT_SEQUENCE_EDITOR="sed -i -e 's/^pick $COMMIT/edit $COMMIT/'" git rebase -i $COMMIT~1^^
- GIT_COMMITTER_NAME="$AUTHOR_NAME" GIT_COMMITTER_EMAIL="$AUTHOR_EMAIL" git commit --amend --no-edit --author="$AUTHOR"
- # git rebase --continue
-} &> /dev/null
-
-echo "$AUTHOR_NAME is now the author of $COMMIT. You're officially an asshole.";
diff --git a/scripts/mail.sh b/scripts/mail.sh
index a7c8208..00c111f 100755
--- a/scripts/mail.sh
+++ b/scripts/mail.sh
@@ -1,3 +1,5 @@
+#!/usr/bin/env bash
+
if [ "$1" = "-s" ]; then
mbsync -aV &>> /tmp/mbsync.log && notmuch new &>> /tmp/notmuch.log
else
diff --git a/scripts/once-only-nextcloud.sh b/scripts/once-only-nextcloud.sh
deleted file mode 100755
index 8400080..0000000
--- a/scripts/once-only-nextcloud.sh
+++ /dev/null
@@ -1,9 +0,0 @@
-#!/bin/sh
-
-if [ "$(pidof nextcloud)" ]
-then
- echo "Nextcloud already running."
-else
- echo "Nextcloud not running yet. Starting it."
- nextcloud & disown
-fi
diff --git a/scripts/once-only-owncloud.sh b/scripts/once-only-owncloud.sh
new file mode 100755
index 0000000..66b3ee4
--- /dev/null
+++ b/scripts/once-only-owncloud.sh
@@ -0,0 +1,9 @@
+#!/usr/bin/env bash
+
+if [ "$(pidof owncloud)" ]
+then
+ echo "ownCloud already running."
+else
+ echo "ownCloud not running yet. Starting it."
+ owncloud & disown
+fi
diff --git a/scripts/single-monitor.sh b/scripts/single-monitor.sh
index ec6c5e2..5b0d03e 100755
--- a/scripts/single-monitor.sh
+++ b/scripts/single-monitor.sh
@@ -1,2 +1,2 @@
-#!/bin/sh
+#!/usr/bin/env bash
xrandr --output VIRTUAL1 --off --output eDP1 --primary --mode 1920x1080 --pos 640x1440 --rotate normal --output DP1 --off --output HDMI2 --off --output HDMI1 --off --output DP2 --off
diff --git a/scripts/sl b/scripts/sl
deleted file mode 100755
index 2333462..0000000
--- a/scripts/sl
+++ /dev/null
@@ -1,13 +0,0 @@
-#!/usr/bin/env bash
-
-# Taken from:
-# https://gir.st/blog/sl-alt.htm
-
-# sl - prints a mirror image of ls. (C) 2017 Tobias Girstmair, https://gir.st/, GPLv3
-
-LEN=$(ls "$@" |wc -L) # get the length of the longest line
-
-ls "$@" | rev | while read -r line
-do
- printf "%${LEN}.${LEN}s\\n" "$line" | sed 's/^\(\s\+\)\(\S\+\)/\2\1/'
-done \ No newline at end of file
diff --git a/scripts/sleepsort b/scripts/sleepsort
deleted file mode 100755
index ea20fcb..0000000
--- a/scripts/sleepsort
+++ /dev/null
@@ -1,20 +0,0 @@
-#!/usr/bin/env bash
-
-# Taken from:
-# https://www.quora.com/What-is-the-strangest-sorting-algorithm/answer/Nipun-Ramakrishnan
-
-function f() {
- sleep "$1"
- echo "$1"
-}
-
-while [ -n "$1" ]
-do
- f "$1" &
- shift
-done
-
-wait
-
-# example usage:
-# sleepsort 5 3 6 3 6 3 1 4 7
diff --git a/scripts/startx b/scripts/startx
index 9b1d153..cca34a2 100644..100755
--- a/scripts/startx
+++ b/scripts/startx
@@ -1,3 +1,3 @@
-#!/bin/sh
+#!/usr/bin/env bash
sudo systemctl restart display-manager &
diff --git a/scripts/three-monitors.sh b/scripts/three-monitors.sh
index d1ef7c6..d8c4e53 100755
--- a/scripts/three-monitors.sh
+++ b/scripts/three-monitors.sh
@@ -1,2 +1,2 @@
-#!/bin/sh
+#!/usr/bin/env bash
xrandr --output VIRTUAL1 --off --output eDP1 --primary --mode 1920x1080 --pos 640x1440 --rotate normal --output DP1 --off --output HDMI2 --off --output HDMI1 --mode 2560x1440 --pos 0x0 --rotate normal --output DP2 --mode 2560x1440 --pos 2560x0 --rotate left