commit 74487a3a833b8901fb6a48a0041c1bc611657a53
parent fae3aa98bf735f9da51d32c14762e514400f421d
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date: Tue, 4 Sep 2018 11:21:05 +0200
Merge branch 'master' of https://gitlab.com/admesg/dotfiles
Diffstat:
7 files changed, 129 insertions(+), 4 deletions(-)
diff --git a/links/.commands.sh b/links/.commands.sh
@@ -3,6 +3,8 @@
#### FUNCTIONS AND ALIASES
+alias z='zsh'
+alias yd='youtube-dl'
## cd
diff --git a/links/.offlineimaprc b/links/.offlineimaprc
@@ -7,7 +7,7 @@
[general]
# List of accounts to be synced, separated by a comma.
#accounts = riseup,geomail
-accounts = adamsgaard,riseup,geomail,gmail,princeton,noaa
+accounts = adamsgaard,riseup,geomail,gmail,princeton
# Suppress nothing but errors
#ui = quiet
ui = ttyui
diff --git a/links/.tmux.conf b/links/.tmux.conf
@@ -162,11 +162,14 @@ bind -T copy-mode-vi v send -X begin-selection # start "visual" with v
# Copy (yank) with y
if-shell 'uname | grep -qi Linux && which xclip > /dev/null' 'bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "DISPLAY=:0 xclip -i -sel clipboard"'
if-shell 'uname | grep -qi Darwin' 'bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "pbcopy"'
+if-shell 'uname | grep -qi Cygwin' 'bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "cat > /dev/clipboard"'
# Paste with C-a p or M-p
if-shell 'uname | grep -qi Linux && which xclip > /dev/null' 'bind p run "DISPLAY=:0 xclip -o | tmux load-buffer - ; tmux paste-buffer"'
if-shell 'uname | grep -qi Darwin && which reattach-to-user-namespace > /dev/null' 'bind p run "pbpaste | tmux load-buffer - ; tmux paste-buffer"'
if-shell 'uname | grep -qi Darwin' 'bind -n M-p run "pbpaste | tmux load-buffer - ; tmux paste-buffer"'
+if-shell 'uname | grep -qi Cygwin' 'bind p run "cat /dev/clipboard | tmux load-buffer - ; tmux paste-buffer"'
+if-shell 'uname | grep -qi Cygwin' 'bind -n M-p run "cat /dev/clipboard | tmux load-buffer - ; tmux paste-buffer"'
#### LAUNCH PROCESSES
diff --git a/links/.vim/ftdetect/qgislayer.vim b/links/.vim/ftdetect/qgislayer.vim
@@ -0,0 +1,4 @@
+augroup qlr_identify
+ autocmd! BufNewFile,BufRead *.qlr setlocal ft=xml
+augroup END
+
diff --git a/links/.zshrc b/links/.zshrc
@@ -220,9 +220,9 @@ zplug load
#### EXTRA COMMANDS
# start ssh-agent
-if [ -z "$SSH_AUTH_SOCK" ]; then
- eval `ssh-agent` && ssh-add
-fi > /dev/null 2>&1
+# if [ -z "$SSH_AUTH_SOCK" ]; then
+# eval `ssh-agent` && ssh-add
+# fi > /dev/null 2>&1
# pass **<tab>
_fzf_complete_pass() {
diff --git a/links/bin/detect_file_changes.sh b/links/bin/detect_file_changes.sh
@@ -0,0 +1,99 @@
+#!/usr/bin/env bash
+
+# Specify the file name for storing the file checksums
+chksumfile=.checksums.txt
+
+# Choice of tool for generating and verifying checksums
+hashgen=sha256sum
+
+function show_help {
+ cat <<-END
+Usage: ${0##*/} [OPTIONS] [FILE]
+Detect changes to files and directory contents using $hashgen checksums.
+Unlike Git and similar, this program does not store file version history.
+
+On the first run, the program stores the directory contents and the file
+cryptographic checksums in a '$chksumfile' file in the current directory. During
+subsequent runs, the directory contents and files are compared to the these
+stored values.
+
+Options:
+ -h, --help show this message
+ - list all files and their checksums to stdout
+ -a, --add FILE update the stored checksum value of FILE
+ -r, --reset reset the values $chksumfile to the current state, which is
+ identical to calling '--add FILE' to all files
+
+This program exits with return status 0 if no changes are found to the stored
+state, and 1 if changes are detected.
+
+Author: Anders Damsgaard anders@adamsgaard.dk, License: GPLv3+
+END
+}
+
+if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
+ show_help
+ exit 0
+fi
+
+# Return checksums for all files in all subdirectories
+function generate_checksums {
+ find . -type f `# search files in all subdirectories` \
+ ! -name "$chksumfile" `# ignore the checksumfile itself` \
+ ! -name "${0##*/}" `# ignore this file` \
+ ! -name ".*.swp" `# ignore editor swap files` \
+ -exec "$hashgen" '{}' + `# run hash command on every found file`
+}
+
+function check_if_file_exists {
+ if [ ! -f "$1" ]; then
+ (<&2 echo "Error: file '$1' was not found")
+ exit 2
+ fi
+}
+
+function update_checksum {
+ file=${1//\//\\\/} # escape forward slashes
+ file=${file//\./\\.} # escape periods
+ file=${file// /\\ } # escape spaces
+ # sed -i '' "s/^.* \*\.$file/$($hashgen $1) *.\/$file/" "$2"
+ grep "$file" $2
+ sed -i '' "s/.*\ $file/asdf/" "$2"
+
+}
+
+if [ ! -f "$chksumfile" ] || [ "$1" = "-r" ] || [ "$1" = "--reset" ]; then
+ # (Over-)write checksum file
+ generate_checksums > "$chksumfile"
+ echo "Checksums stored in $chksumfile"
+
+elif [ "$1" = "-a" ] || [ "$1" = "--add" ]; then
+ for file in "${@:2}"; do
+ check_if_file_exists "$file"
+ done
+ # Update checksums for all specified files
+ for file in "${@:2}"; do
+ update_checksum "$file" "$chksumfile"
+ done
+
+elif [ "$1" = "-" ]; then
+ # Print checksums and file paths to stdout
+ generate_checksums
+
+else
+ # Compare current checksums against stored values
+ generate_checksums \
+ | diff "$chksumfile" - `# compare stored checksums with current vals` \
+ | sed 's/>/new: /' `# replace > with new:` \
+ | sed 's/</rem: /' `# replace < with rem:` \
+ | sed 's/\*\.\///' `# simplify file path`
+ #| awk '{ print $1 $3 }' `# hide checksum in second column` \
+
+ # Report if the diff command returned with status 0
+ if [ ${PIPESTATUS[1]} -eq 0 ]; then
+ echo "No file changes detected"
+ else
+ # Return exit status 1 if something changed
+ exit 1
+ fi
+fi
diff --git a/links/bin/watch.sh b/links/bin/watch.sh
@@ -0,0 +1,17 @@
+#!/usr/bin/env bash
+set -e
+
+waitsecs=5
+
+if [ $# -lt 1 ]; then
+ (>&2 echo "Error: $0 needs to be passed a command");
+ exit 1
+fi
+
+while : ; do
+ clear
+ echo -n "Every ${waitsecs}s: $@"
+ echo -e "\t $(hostname): $(date)\n"
+ "$@"
+ sleep "$waitsecs"
+done