dotfiles

My dotfiles, nothing really interesting to see ...
git clone https://git.onna.be/dotfiles.git
Log | Files | Refs | README

commit f7cbbebcd2c886d34091cbb2c3fecbd89c16cc93
parent 47a8d6c31a134c45cd76a8e80b6c8a94a35b8169
Author: Paco Esteban <paco@onna.be>
Date:   Sat, 23 Jun 2018 19:42:49 +0200

better Makefile and bin is now as the rest

Diffstat:
Makefile | 59++++++++++-------------------------------------------------
bin/b2h | 2--
bin/b2o | 2--
bin/backup.sh | 57---------------------------------------------------------
bin/bin/b2h | 2++
bin/bin/b2o | 2++
bin/bin/backup.sh | 57+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
bin/bin/convertBase.py | 63+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
bin/bin/d2b | 2++
bin/bin/d2h | 2++
bin/bin/d2o | 2++
bin/bin/h2b | 2++
bin/bin/h2o | 2++
bin/bin/hex_print | 32++++++++++++++++++++++++++++++++
bin/bin/o2b | 2++
bin/bin/o2h | 2++
bin/bin/ssync.sh | 26++++++++++++++++++++++++++
bin/convertBase.py | 63---------------------------------------------------------------
bin/d2b | 2--
bin/d2h | 2--
bin/d2o | 2--
bin/h2b | 2--
bin/h2o | 2--
bin/hex_print | 32--------------------------------
bin/o2b | 2--
bin/o2h | 2--
bin/ssync.sh | 26--------------------------
27 files changed, 206 insertions(+), 245 deletions(-)

diff --git a/Makefile b/Makefile @@ -1,59 +1,20 @@ -UNAME_S := $(shell uname -s) -ifeq ($(UNAME_S),Linux) - UNAME = Linux -endif -ifeq ($(UNAME_S),Darwin) - UNAME = OSX -endif +PACKAGES := $(shell find ${PWD} -name ".*" -prune -o -maxdepth 1 -type d -print | sed "s:${PWD}::" |sed 's:/::') + +UNAME := $(shell uname -s) install: @make $(UNAME) -OSX: bin zsh nvim tmux git tidy +Darwin: bin zsh nvim tmux git tidy Linux: bin zsh nvim tmux git tidy i3 +OpenBSD: bin zsh nvim tmux git tidy i3 clean: @echo "- CLEAN --------------------" - stow -t "$$HOME/bin" -D bin - stow -t "$$HOME" -D git - stow -t "$$HOME" -D i3 - stow -t "$$HOME" -D nvim - stow -t "$$HOME" -D tidy - stow -t "$$HOME" -D tmux - stow -t "$$HOME" -D x11 - stow -t "$$HOME" -D zsh - -bin: - @echo "- BIN ----------------------" - stow -t "$$HOME/bin" bin - -git: - @echo "- GIT ----------------------" - stow -t "$$HOME" git - -i3: - @echo "- i3 -----------------------" - stow -t "$$HOME" i3 - stow -t "$$HOME" polybar - -nvim: - @echo "- NVIM ---------------------" - stow -t "$$HOME" nvim - -tidy: - @echo "- STYLE and TIDY -----------" - stow -t "$$HOME" tidy - -tmux: - @echo "- TMUX ---------------------" - stow -t "$$HOME" tmux - -x11: - @echo "- X11 ----------------------" - stow -t "$$HOME" x11 + stow -t "$$HOME" -D ${PACKAGES} -zsh: - @echo "- ZSH ----------------------" - stow -t "$$HOME" zsh +${PACKAGES}: + @echo "- $@ -------------------------" + stow -t "$$HOME" $@ -.PHONY: install Linux OSX zsh nvim tmux i3 git tidy bin x11 +.PHONY: install Linux Darwin OpenBSD ${PACKAGES} diff --git a/bin/b2h b/bin/b2h @@ -1 +0,0 @@ -convertBase.py- \ No newline at end of file diff --git a/bin/b2o b/bin/b2o @@ -1 +0,0 @@ -convertBase.py- \ No newline at end of file diff --git a/bin/backup.sh b/bin/backup.sh @@ -1,57 +0,0 @@ -#!/usr/bin/env bash - -# ======================================================================== -# = Rsync based backup script. -# = It uses the '--link-dest' option of rsync to create hard links to the -# = previous full backup. So incremental + full all in one. -# = -# = backup.sh <ORIG_DIR> <DEST_DIR> [RETENTION] [FILELIST] -# = <ORIG_DIR> origin resource, can be a folder local or remote -# = <DEST_DIR> destination resource, can be a folder local or remote -# = [RETENTION] number of days for backup retention (default: 30) -# = [FILELIST] list of files to backup exclusively (recursive) -# ======================================================================== - -ORIG_DIR="$1" -DEST_DIR="$2" -DATE=$(/bin/date +%Y%m%d%H%M) -RETENTION=${3:-30} -FILELIST="$4" -RSYNC_OPTIONS=() - -if [[ -z "$ORIG_DIR" || -z "$DEST_DIR" ]]; then - echo "ORIG_DIR and DEST_DIR are mandatory !!" - exit 1 -fi - -# delete older than $RETENTION days -echo "** deleting files older than $RETENTION days ..." -find "$DEST_DIR" -maxdepth 1 -name "????????????" -mtime "+$RETENTION" -delete - -LAST_BACKUP=$(find "$DEST_DIR" -maxdepth 1 -name "????????????" | sort | tail -1) - -# if LAST_BACKUP does not exist, it's our first run -if [[ ! -z "$LAST_BACKUP" ]]; then - RSYNC_OPTIONS+=("--link-dest=$LAST_BACKUP") -fi - -if [[ ! -z "$FILELIST" ]]; then - RSYNC_OPTIONS+=("--files-from=$FILELIST") -fi - -# and now we run rsync -echo "** backing up $ORIG_DIR - $DATE ..." -mkdir "$DEST_DIR/$DATE" -rsync -azr --numeric-ids "${RSYNC_OPTIONS[@]}" "$ORIG_DIR/" "$DEST_DIR/$DATE/" -RET="$?" - -# touch to make rsync and find play nice with each other -touch "$DEST_DIR/$DATE" - -if [[ "$RET" != "0" ]] -then - echo "!! Backup Error (rsync) !!" - exit 1 -fi - -echo "done." diff --git a/bin/bin/b2h b/bin/bin/b2h @@ -0,0 +1 @@ +convertBase.py+ \ No newline at end of file diff --git a/bin/bin/b2o b/bin/bin/b2o @@ -0,0 +1 @@ +convertBase.py+ \ No newline at end of file diff --git a/bin/bin/backup.sh b/bin/bin/backup.sh @@ -0,0 +1,57 @@ +#!/usr/bin/env bash + +# ======================================================================== +# = Rsync based backup script. +# = It uses the '--link-dest' option of rsync to create hard links to the +# = previous full backup. So incremental + full all in one. +# = +# = backup.sh <ORIG_DIR> <DEST_DIR> [RETENTION] [FILELIST] +# = <ORIG_DIR> origin resource, can be a folder local or remote +# = <DEST_DIR> destination resource, can be a folder local or remote +# = [RETENTION] number of days for backup retention (default: 30) +# = [FILELIST] list of files to backup exclusively (recursive) +# ======================================================================== + +ORIG_DIR="$1" +DEST_DIR="$2" +DATE=$(/bin/date +%Y%m%d%H%M) +RETENTION=${3:-30} +FILELIST="$4" +RSYNC_OPTIONS=() + +if [[ -z "$ORIG_DIR" || -z "$DEST_DIR" ]]; then + echo "ORIG_DIR and DEST_DIR are mandatory !!" + exit 1 +fi + +# delete older than $RETENTION days +echo "** deleting files older than $RETENTION days ..." +find "$DEST_DIR" -maxdepth 1 -name "????????????" -mtime "+$RETENTION" -delete + +LAST_BACKUP=$(find "$DEST_DIR" -maxdepth 1 -name "????????????" | sort | tail -1) + +# if LAST_BACKUP does not exist, it's our first run +if [[ ! -z "$LAST_BACKUP" ]]; then + RSYNC_OPTIONS+=("--link-dest=$LAST_BACKUP") +fi + +if [[ ! -z "$FILELIST" ]]; then + RSYNC_OPTIONS+=("--files-from=$FILELIST") +fi + +# and now we run rsync +echo "** backing up $ORIG_DIR - $DATE ..." +mkdir "$DEST_DIR/$DATE" +rsync -azr --numeric-ids "${RSYNC_OPTIONS[@]}" "$ORIG_DIR/" "$DEST_DIR/$DATE/" +RET="$?" + +# touch to make rsync and find play nice with each other +touch "$DEST_DIR/$DATE" + +if [[ "$RET" != "0" ]] +then + echo "!! Backup Error (rsync) !!" + exit 1 +fi + +echo "done." diff --git a/bin/bin/convertBase.py b/bin/bin/convertBase.py @@ -0,0 +1,63 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# vim:fenc=utf-8 + +import sys +from os.path import basename + +if len(sys.argv) != 2: + print("Wrong number of arguments") + sys.exit(1) + +script_name = basename(sys.argv[0]) +res = [] + +if script_name == 'd2b': + base = 10 + bits = 4 + nformat = "{:04b}" +elif script_name == 'd2o': + base = 10 + bits = 7 + nformat = "{:03o}" +elif script_name == 'd2h': + base = 10 + bits = 8 + nformat = "{:02x}" +elif script_name == 'b2h': + base = 2 + bits = 8 + nformat = "{:02x}" +elif script_name == 'b2o': + base = 2 + bits = 7 + nformat = "{:03o}" +elif script_name == 'o2b': + base = 8 + bits = 4 + nformat = "{:04b}" +elif script_name == 'o2h': + base = 8 + bits = 8 + nformat = "{:02x}" +elif script_name == 'h2o': + base = 16 + bits = 7 + nformat = "{:03o}" +elif script_name == 'h2b': + base = 16 + bits = 4 + nformat = "{:04b}" +else: + print("Unrecognized command {}".format(script_name)) + sys.exit(1) + +n = int(sys.argv[1], base) +mask = (1 << bits) - 1 + +while n > 0: + chunk = n & mask + res.insert(0, nformat.format(chunk)) + n = n >> bits + +print(" ".join(res)) diff --git a/bin/bin/d2b b/bin/bin/d2b @@ -0,0 +1 @@ +convertBase.py+ \ No newline at end of file diff --git a/bin/bin/d2h b/bin/bin/d2h @@ -0,0 +1 @@ +convertBase.py+ \ No newline at end of file diff --git a/bin/bin/d2o b/bin/bin/d2o @@ -0,0 +1 @@ +convertBase.py+ \ No newline at end of file diff --git a/bin/bin/h2b b/bin/bin/h2b @@ -0,0 +1 @@ +convertBase.py+ \ No newline at end of file diff --git a/bin/bin/h2o b/bin/bin/h2o @@ -0,0 +1 @@ +convertBase.py+ \ No newline at end of file diff --git a/bin/bin/hex_print b/bin/bin/hex_print @@ -0,0 +1,32 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +import fileinput +import sys + +line = "" + +# nasty trick to either take stdin or param 1 +if len(sys.argv) < 2: + for l in fileinput.input(): + line += l +else: + line = sys.argv[1] + +chunk_size = 16 + +# split line in chunks of 16 bytes +for i in range(0, len(line), chunk_size): + chunk = line[i:i + chunk_size] + # transform to list, as strings are inmutable in python + chunk_list = list(chunk) + # iterate and substitute any non-printable char + for i, c in enumerate(chunk_list): + if ord(c) < 0x20 or ord(c) > 0x7e: + chunk_list[i] = '¤' + # back to string + chunk_filtered = ''.join(chunk_list) + # clever way to transform the original string to hex bytes + chunk_hex = " ".join("{:02x}".format(ord(c)) for c in chunk) + # print it all, similar to hexdump output + print("{:47} {}".format(chunk_hex, chunk_filtered)) diff --git a/bin/bin/o2b b/bin/bin/o2b @@ -0,0 +1 @@ +convertBase.py+ \ No newline at end of file diff --git a/bin/bin/o2h b/bin/bin/o2h @@ -0,0 +1 @@ +convertBase.py+ \ No newline at end of file diff --git a/bin/bin/ssync.sh b/bin/bin/ssync.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +DIRECTION=${1} +if [[ -z "$DIRECTION" ]]; then + echo "Need directio (from | to)" + exit 1 +fi + +if [[ "$DIRECTION" == "to" ]]; then + FROM="$HOME/Sync/" + TO="galadriel:Sync/" +else + FROM="galadriel:Sync/" + TO="$HOME/Sync/" +fi +shift + +rsync \ + -av \ + $* \ + --delete \ + --exclude '*.pyc' \ + --exclude '__pycache__' \ + --exclude 'src/go/bin/*' \ + $FROM \ + $TO diff --git a/bin/convertBase.py b/bin/convertBase.py @@ -1,63 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -# vim:fenc=utf-8 - -import sys -from os.path import basename - -if len(sys.argv) != 2: - print("Wrong number of arguments") - sys.exit(1) - -script_name = basename(sys.argv[0]) -res = [] - -if script_name == 'd2b': - base = 10 - bits = 4 - nformat = "{:04b}" -elif script_name == 'd2o': - base = 10 - bits = 7 - nformat = "{:03o}" -elif script_name == 'd2h': - base = 10 - bits = 8 - nformat = "{:02x}" -elif script_name == 'b2h': - base = 2 - bits = 8 - nformat = "{:02x}" -elif script_name == 'b2o': - base = 2 - bits = 7 - nformat = "{:03o}" -elif script_name == 'o2b': - base = 8 - bits = 4 - nformat = "{:04b}" -elif script_name == 'o2h': - base = 8 - bits = 8 - nformat = "{:02x}" -elif script_name == 'h2o': - base = 16 - bits = 7 - nformat = "{:03o}" -elif script_name == 'h2b': - base = 16 - bits = 4 - nformat = "{:04b}" -else: - print("Unrecognized command {}".format(script_name)) - sys.exit(1) - -n = int(sys.argv[1], base) -mask = (1 << bits) - 1 - -while n > 0: - chunk = n & mask - res.insert(0, nformat.format(chunk)) - n = n >> bits - -print(" ".join(res)) diff --git a/bin/d2b b/bin/d2b @@ -1 +0,0 @@ -convertBase.py- \ No newline at end of file diff --git a/bin/d2h b/bin/d2h @@ -1 +0,0 @@ -convertBase.py- \ No newline at end of file diff --git a/bin/d2o b/bin/d2o @@ -1 +0,0 @@ -convertBase.py- \ No newline at end of file diff --git a/bin/h2b b/bin/h2b @@ -1 +0,0 @@ -convertBase.py- \ No newline at end of file diff --git a/bin/h2o b/bin/h2o @@ -1 +0,0 @@ -convertBase.py- \ No newline at end of file diff --git a/bin/hex_print b/bin/hex_print @@ -1,32 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- - -import fileinput -import sys - -line = "" - -# nasty trick to either take stdin or param 1 -if len(sys.argv) < 2: - for l in fileinput.input(): - line += l -else: - line = sys.argv[1] - -chunk_size = 16 - -# split line in chunks of 16 bytes -for i in range(0, len(line), chunk_size): - chunk = line[i:i + chunk_size] - # transform to list, as strings are inmutable in python - chunk_list = list(chunk) - # iterate and substitute any non-printable char - for i, c in enumerate(chunk_list): - if ord(c) < 0x20 or ord(c) > 0x7e: - chunk_list[i] = '¤' - # back to string - chunk_filtered = ''.join(chunk_list) - # clever way to transform the original string to hex bytes - chunk_hex = " ".join("{:02x}".format(ord(c)) for c in chunk) - # print it all, similar to hexdump output - print("{:47} {}".format(chunk_hex, chunk_filtered)) diff --git a/bin/o2b b/bin/o2b @@ -1 +0,0 @@ -convertBase.py- \ No newline at end of file diff --git a/bin/o2h b/bin/o2h @@ -1 +0,0 @@ -convertBase.py- \ No newline at end of file diff --git a/bin/ssync.sh b/bin/ssync.sh @@ -1,26 +0,0 @@ -#!/usr/bin/env bash - -DIRECTION=${1} -if [[ -z "$DIRECTION" ]]; then - echo "Need directio (from | to)" - exit 1 -fi - -if [[ "$DIRECTION" == "to" ]]; then - FROM="$HOME/Sync/" - TO="galadriel:Sync/" -else - FROM="galadriel:Sync/" - TO="$HOME/Sync/" -fi -shift - -rsync \ - -av \ - $* \ - --delete \ - --exclude '*.pyc' \ - --exclude '__pycache__' \ - --exclude 'src/go/bin/*' \ - $FROM \ - $TO