From ff3faccd4e6212a01a8333dfdbd076b996d7de50 Mon Sep 17 00:00:00 2001 From: Vincent Composieux Date: Sat, 16 Sep 2017 10:56:23 +0200 Subject: [PATCH] Added .functions file --- .functions | 40 ++++++++++++++++++++++++++++++++++++++++ Makefile | 1 + 2 files changed, 41 insertions(+) create mode 100644 .functions diff --git a/.functions b/.functions new file mode 100644 index 0000000..8356ea9 --- /dev/null +++ b/.functions @@ -0,0 +1,40 @@ +# Clones if a Git repository is given, elsewhere just cd +function cdc() { + name=`sed -e 's/.*\///g' <<< $1` + + if [[ ! -d "$1" && $1 =~ ^(github|bitbucket|gitlab)\.[a-z]{2,}/.*$ ]]; then + ssh=`sed -e 's/^/git@/' -e 's/$/.git/' -e 's/\//:/' <<< $1` + git clone $ssh; + fi + + cd $name; +} + +# Determines 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; +} + +# Creates a data URL from a file +function dataurl() { + local mimeType=$(file -b --mime-type "$1"); + if [[ $mimeType == text/* ]]; then + mimeType="${mimeType};charset=utf-8"; + fi + echo "data:${mimeType};base64,$(openssl base64 -in "$1" | tr -d '\n')"; +} + +# Returns useful information using dig tool +function digga() { + dig +nocmd "$1" any +multiline +noall +answer; +} + diff --git a/Makefile b/Makefile index 322d359..26e8e99 100644 --- a/Makefile +++ b/Makefile @@ -11,6 +11,7 @@ install: ## Installs dotfiles into current environment @$(MAKE) DOTFILE=.hyper.js install_file @$(MAKE) DOTFILE=.aliases install_file @$(MAKE) DOTFILE=.exports install_file + @$(MAKE) DOTFILE=.functions install_file @$(MAKE) DOTFILE=.sources install_file @$(MAKE) DOTFILE=.zshrc install_file