This commit is contained in:
Martin Donnelly 2021-11-23 12:06:56 +00:00
parent b85da4c8b8
commit 874013fb65
4 changed files with 199 additions and 8 deletions

View File

@ -57,4 +57,3 @@ alias egrep='egrep --color=auto'
alias dlyoutube="youtube-dl -f bestaudio --audio-quality 0 --audio-format aac " alias dlyoutube="youtube-dl -f bestaudio --audio-quality 0 --audio-format aac "
alias bat='upower -i /org/freedesktop/UPower/devices/battery_BAT0| grep -E "state|to\ full|percentage|capacity"' alias bat='upower -i /org/freedesktop/UPower/devices/battery_BAT0| grep -E "state|to\ full|percentage|capacity"'

View File

@ -1,6 +1,186 @@
function appBoilerplate(){ #!/usr/bin/env bash
git clone -b boilerplates --depth=1 git@gitlab.dev.fsbtech.com:frontend/whitelabel-utils.git boilerplates \
&& cp -r boilerplates/core_app/ ./$1_app || rm -rf boilerplates \ function docker_cleanup() {
&& rm -rf boilerplates \ sudo docker rm -v $(sudo docker ps -a -q -f status=exited)
&& for i in $1_app/*genericAppName* ; do mv "$i" "${i/genericAppName/$1}" ; done \ sudo docker rmi -f $(sudo docker images -f "dangling=true" -q)
} docker volume ls -qf dangling=true | xargs -r docker volume rm
}
function cleanup_docker() {
docker ps -f status=exited -q | xargs -r docker rm
docker images -f dangling=true -q | xargs -r docker rmi
}
function cleanup_docker_aggressive() {
for i in $(docker images --no-trunc -q | sort -u); do
docker rmi $i 2>/dev/null
done
}
# Determine size of a file or total size of a directory
function fs() {
if du -b /dev/null >/dev/null 2>&1; then
local arg=-sbh
else
local arg=-sh
fi
if [[ -n "$@" ]]; then
du $arg -- "$@"
else
du $arg .[^.]* ./*
fi
}
# Create a .tar.gz archive, using `zopfli`, `pigz` or `gzip` for compression
function targz() {
local tmpFile="${@%/}.tar"
tar -cvf "${tmpFile}" --exclude={".DS_Store","node_modules",".idea",".git"} "${@}" || return 1
size=$(
stat -f"%z" "${tmpFile}" 2>/dev/null # macOS `stat`
stat -c"%s" "${tmpFile}" 2>/dev/null # GNU `stat`
)
local cmd=""
if ((size < 52428800)) && hash zopfli 2>/dev/null; then
# the .tar file is smaller than 50 MB and Zopfli is available; use it
cmd="zopfli"
else
if hash pigz 2>/dev/null; then
cmd="pigz"
else
cmd="gzip"
fi
fi
echo "Compressing .tar ($((size / 1000)) kB) using \`${cmd}\`…"
"${cmd}" -v "${tmpFile}" || return 1
[ -f "${tmpFile}" ] && rm "${tmpFile}"
zippedSize=$(
stat -f"%z" "${tmpFile}.gz" 2>/dev/null # macOS `stat`
stat -c"%s" "${tmpFile}.gz" 2>/dev/null # GNU `stat`
)
echo "${tmpFile}.gz ($((zippedSize / 1000)) kB) created successfully."
}
# Print README file
readme() {
for readme in {readme,README}.{md,MD,markdown,mkd,txt,TXT}; do
if [[ -x "$(command -v glow)" ]] && [[ -f "$readme" ]]; then
mdv "$readme"
elif [[ -f "$readme" ]]; then
cat "$readme"
fi
done
}
# Get an information of IP address
ip-address() {
curl -s -H "Accept: application/json" "https://ipinfo.io/${1:-}" | jq "del(.loc, .postal, .readme)"
}
topfiles() {
du -M --max-depth=1 $1 | sort -n | tail -n 5
}
store() {
DNOW=$(date '+%F-%H-%M')
local tmpFile="${@%/}-${DNOW}.tar"
tar -cvf "${tmpFile}" --exclude={".DS_Store","node_modules",".idea",".git"} "${@}" || return 1
size=$(
stat -f"%z" "${tmpFile}" 2>/dev/null # macOS `stat`
stat -c"%s" "${tmpFile}" 2>/dev/null # GNU `stat`
)
local cmd=""
if ((size < 52428800)) && hash zopfli 2>/dev/null; then
# the .tar file is smaller than 50 MB and Zopfli is available; use it
cmd="zopfli"
else
if hash pigz 2>/dev/null; then
cmd="pigz"
else
cmd="gzip"
fi
fi
echo "Compressing .tar ($((size / 1000)) kB) using \`${cmd}\`…"
"${cmd}" -9 -v "${tmpFile}" || return 1
[ -f "${tmpFile}" ] && rm "${tmpFile}"
zippedSize=$(
stat -f"%z" "${tmpFile}.gz" 2>/dev/null # macOS `stat`
stat -c"%s" "${tmpFile}.gz" 2>/dev/null # GNU `stat`
)
echo "Used ${cmd} to compress"
echo "${tmpFile}.gz ($((zippedSize / 1000)) kB) created successfully."
}
wip() {
WORK_DIR="/home/martin/dev/wip"
echo "WIP Update:${@%}"
DEST="$WORK_DIR/${@%}"
echo $DEST
mkdir -p $DEST
# mkdir ./wip/${@%}
rsync -auzvh --itemize-changes --progress --delete --delete-excluded --ignore-errors --exclude 'node_modules' --exclude 'bower_components' --exclude '.git' --exclude '.tmp' ${@%}/ $DEST/
echo Compress $DEST/
store $DEST/
# mv $WORK_DIR/wip/*.tar.gz $HOME/dev/wip
}
gitdiff() {
line=$(git log $1^..$2 --pretty=format:%s)
SAVEIFS=$IFS # Save current IFS
IFS=$'\n' # Change IFS to new line
names=($line) # split to array $names
IFS=$SAVEIFS # Restore IFS
testseq="Merge branch"
# for (( i=0; i<${#names[@]}; i++ ))
# do
# echo "${names[$i]}"
# done
for s in "${names[@]}"; do
if ! [[ $s =~ $testseq ]]; then
# echo $s
parsed='\'$s
result=$(git log --all --grep="${parsed}" --pretty=format:"%h")
echo $parsed
for COMMIT in $result; do
echo "git $COMMIT"
### echo $(git branch --contains $COMMIT --color "$3" | sed 's/[*]\+//g' )
done
echo "---"
fi
done
}

View File

@ -1,4 +1,9 @@
[alias] [alias]
# tidy up a dirty branch
# cu = !"git stash --include-untracked"
cu = !"git clean -df; git checkout --"
# Better update than just git pull # Better update than just git pull
up = !"git remote update -p; git merge --ff-only @{u}" up = !"git remote update -p; git merge --ff-only @{u}"
@ -105,6 +110,7 @@
editor = 'nano' editor = 'nano'
autocrlf = input autocrlf = input
excludefile = /home/martin/.gitignore
[color] [color]
branch = always branch = always
@ -197,4 +203,6 @@
insteadOf = "gist:" insteadOf = "gist:"
[user] [user]
name = Martin Donnelly name = Martin Donnelly
email = martin@fsbtech.com email = martin.donnelly@beeksgroup.com
[credential]
helper = cache --timeout=7200

View File

@ -0,0 +1,4 @@
.DS_Store
.vscode
.idea