Files
dotfiles/functions
Eragos 54857b2b83 test
## To make a commit, type your commit message and press SUPER-ENTER. To cancel
## the commit, close the window. To sign off on the commit, press SUPER-S.

## You may also reference or close a GitHub issue with this commit.  To do so,
## type `#` followed by the `tab` key.  You will be shown a list of issues
## related to the current repo.  You may also type `owner/repo#` plus the `tab`
## key to reference an issue in a different GitHub repo.

diff --git a/functions b/functions
index 52bf5ee..a8717f3 100644
--- a/functions
+++ b/functions
@@ -3,7 +3,7 @@ udot() {
   info=$(git --no-pager log --pretty="%h by %an <%ae> on %cd" -1 --abbrev-commit)
   local=$(git --no-pager log --pretty="%H" -1)
   remote=$(git ls-remote origin | awk "/HEAD/ {print \$1}")
-  gstatus=$(git status -s)
+  gstatus=$(git status --porcelain)

   echo -e ""
   echo -e '    ____      U  ___ u _____    _____              _     U _____ u ____    '
@@ -17,7 +17,7 @@ udot() {
   echo -e "$info"
   echo -e ""

-  if [ "$status" != "" ]; then
+  if [ -n "$status" ]; then
     echo -e "Local changes:"
     echo -e "$gstatus"
     echo -e ""
2016-07-12 00:03:39 +02:00

135 lines
4.1 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Update dotfiles
udot() {
info=$(git --no-pager log --pretty="%h by %an <%ae> on %cd" -1 --abbrev-commit)
local=$(git --no-pager log --pretty="%H" -1)
remote=$(git ls-remote origin | awk "/HEAD/ {print \$1}")
gstatus=$(git status --porcelain)
echo -e ""
echo -e ' ____ U ___ u _____ _____ _ U _____ u ____ '
echo -e ' | _"\ \/"_ \/|_ " _| |" ___| ___ |"| \| ___"|// __"| u '
echo -e ' /| | | | | | | | | | U| |_ u |_"_| U | | u | _|" <\___ \/ '
echo -e ' U| |_| |\.-,_| |_| | /| |\ \| _|/ | | \| |/__ | |___ u___) | '
echo -e ' |____/ u \_)-\___/ u |_|U |_| U/| |\u |_____| |_____| |____/>> '
echo -e ' |||_ \\\\ _// \\\\_ )(\\\\,-.-,_|___|_,-.// \\\\ << >> )( (__)'
echo -e ' (__)_) (__) (__) (__)(__)(_/ \_)-´ `-(_/(_")("_)(__) (__)(__) '
echo -e ""
echo -e "$info"
echo -e ""
if [ -n "$status" ]; then
echo -e "Local changes:"
echo -e "$gstatus"
echo -e ""
fi
if [ "$local" = "$remote" ]; then
echo "Already up to date :)"
else
echo -e "Updating..."
cwd=$(pwd)
cd ~/.dotfiles/
git pull
bin/dfm install
source ~/.dotfiles/aliases
source ~/.dotfiles/functions
cd $cwd
fi
echo -e ""
}
# will attach to existing tmux session, create new if one does not exist or just start bash if there is no tmux available.
function ssht(){
ssh $* -t 'tmux a || tmux || /bin/bash'
}
#Docker: bash into running Docker container
dockersh() {
docker cp ~/.dotfiles/docker.bashrc $1:/.docker.bashrc
docker cp ~/.dotfiles/aliases $1:/.docker.aliases
docker cp ~/.dotfiles/functions $1:/.docker.functions
docker exec -it $1 bash --rcfile /.docker.bashrc
}
#Docker: bash into running Docker container
dockerlog() {
docker logs -f $1
}
#Docker: run docker security check
dockersecure() {
docker run -it --net host --pid host --cap-add audit_control -v /var/lib:/var/lib -v /var/run/docker.sock:/var/run/docker.sock -v /usr/lib/systemd:/usr/lib/systemd -v /etc:/etc --label docker_bench_security --rm docker/docker-bench-security
}
# WRK
function wrk() {
docker run --rm williamyeh/wrk --latency $1
}
# Simple calculator
function calc() {
local result="";
result="$(printf "scale=10;$*\n" | bc --mathlib | tr -d '\\\n')";
# └─ default (when `--mathlib` is used) is 20
#
if [[ "$result" == *.* ]]; then
# improve the output for decimal numbers
printf "$result" |
sed -e 's/^\./0./' `# add "0" for cases like ".5"` \
-e 's/^-\./-0./' `# add "0" for cases like "-.5"`\
-e 's/0*$//;s/\.$//'; # remove trailing zeros
else
printf "$result";
fi;
printf "\n";
}
# Create a new directory and enter it
function mcd() {
mkdir -p "$@" && cd "$_";
}
# Run `dig` and display the most useful info
function digga() {
dig +nocmd "$1" any +multiline +noall +answer;
}
# Search in bash history
function his() {
history | grep --color=auto -i "$1";
}
# Decompress just about any compressed file format
function extract {
if [ -z "$1" ]; then
# display usage if no parameters given
echo "Usage: extract <path/file_name>.<zip|rar|bz2|gz|tar|tbz2|tgz|Z|7z|xz|ex|tar.bz2|tar.gz|tar.xz>"
else
if [ -f $1 ] ; then
# NAME=${1%.*}
# mkdir $NAME && cd $NAME
case $1 in
*.tar.bz2) tar xvjf ../$1 ;;
*.tar.gz) tar xvzf ../$1 ;;
*.tar.xz) tar xvJf ../$1 ;;
*.lzma) unlzma ../$1 ;;
*.bz2) bunzip2 ../$1 ;;
*.rar) unrar x -ad ../$1 ;;
*.gz) gunzip ../$1 ;;
*.tar) tar xvf ../$1 ;;
*.tbz2) tar xvjf ../$1 ;;
*.tgz) tar xvzf ../$1 ;;
*.zip) unzip ../$1 ;;
*.Z) uncompress ../$1 ;;
*.7z) 7z x ../$1 ;;
*.xz) unxz ../$1 ;;
*.exe) cabextract ../$1 ;;
*) echo "extract: '$1' - unknown archive method" ;;
esac
else
echo "$1 - file does not exist"
fi
fi
}