myfind and mypath interactive bash session helper function.
authorOleksandr Gavenko <gavenkoa@gmail.com>
Wed, 10 Sep 2014 03:04:57 +0300
changeset 704 e1347fd80853
parent 703 fc6805490326
child 705 4a77587b0617
myfind and mypath interactive bash session helper function.
.bashrc
--- a/.bashrc	Wed Aug 27 23:32:53 2014 +0300
+++ b/.bashrc	Wed Sep 10 03:04:57 2014 +0300
@@ -107,6 +107,24 @@
 # make and change to a directory
 md () { mkdir -p "$1" && cd "$1"; }
 
+myfind() { find . -iname "$1"; }
+mypath() {
+  local var="$2"
+  [[ -z $var ]] && var=PATH
+  local delim="$3"
+  [[ -z $delim ]] && delim=:
+  local split
+  IFS="$delim" command eval "read -ra split <<< \"\${$var}\""
+  for dir in "${split[@]}"; do
+    [[ -z "$dir" ]] && continue
+    if [[ -f "$dir"/"$1" ]]; then
+      echo "$dir"/"$1"
+    else
+      ls -d "$dir"/$1 2>/dev/null | cat
+    fi
+  done
+}
+
 # LANG=C for speed.
 alias grep='GREP_COLOR="31;47" LANG=C grep -n --color=auto'
 alias ls='ls --color=auto'