From 811f0e5ab542979826db1dfb1dbaa8da4b8fd447 Mon Sep 17 00:00:00 2001 From: Hari Sekhon Date: Sun, 11 Aug 2019 15:45:00 +0100 Subject: [PATCH] migrated more functions --- .bash.d/functions.sh | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/.bash.d/functions.sh b/.bash.d/functions.sh index ed5f9b63..29ea5c1f 100644 --- a/.bash.d/functions.sh +++ b/.bash.d/functions.sh @@ -44,6 +44,26 @@ hr(){ echo "# ============================================================================ #" } +repeat(){ + local i n + n="$1" + shift + if [ -z "$n" ]; then + echo "usage: repeat N command args" + return 1 + fi + for ((i=1; i <= n; i++)); do + "$@" + done +} + +loop(){ + while true; do + eval "${*//\$/\\$}" + sleep 1 + done +} + topcommands(){ # first awk print $2 but my advanced history records `date '+%F %T'` in between number and command for $2 and $3, making command $4 history | @@ -83,6 +103,12 @@ f(){ eval find -L . -type f "$grep" } +add_etc_host(){ + local host_line="$*" + $sudo grep -q "^$host_line" /etc/hosts || + $sudo echo "$host_line" >> /etc/hosts +} + vihosts(){ [ $EUID -eq 0 ] && sudo="" || sudo=sudo $sudo vim /etc/hosts