Browse Source

Adding some new functions

Sam Jaffe 7 years ago
parent
commit
8332ab8566
2 changed files with 40 additions and 0 deletions
  1. 1 0
      profile-git
  2. 39 0
      profile-util

+ 1 - 0
profile-git

@@ -27,4 +27,5 @@ git-create() {
 }
 
 alias git-graph="git log --graph --pretty=oneline --abbrev-commit --decorate --all"
+alias git-cleanup='git branch --merged | egrep -v "(^\*|master|dev)" | xargs git branch -d'
 

+ 39 - 0
profile-util

@@ -151,6 +151,45 @@ clrun() {
   "$@"
 }
 
+_total_on_bottom() {
+  local cap=""
+  while read line; do
+    if [[ ${line} =~ .*total$ ]]; then
+      local cap="${line}"
+    else
+      echo "${line}"
+    fi
+  done
+  if [[ -n "${cap}" ]]; then
+    echo "${cap}"
+  fi
+}
+
+_rlall_noself() {
+  for i in "$@"; do
+    [[ $(basename ${i}) =~ ^\.\.?$ ]] || readlink -f "${i}"
+  done
+}
+
+dus() {
+  if [[ ${1} == "-a" ]]; then
+    IFS=$'\n' args=($(_rlall_noself "${2}/"* "${2}/".* )); unset IFS
+  elif [[ ${1} == "-d" ]]; then
+    IFS=$'\n' args=($(_rlall_noself "${2}/"* )); unset IFS
+  else
+    IFS=$'\n' args=($(_rlall_noself "$@")); unset IFS
+  fi
+  du -shc "${args[@]}" | sort -h | _total_on_bottom
+}
+
+repeat() {
+  local n=$1
+  shift
+  for ((i=0;i<n;++i)); do 
+    "$@"
+  done
+}
+
 if [[ $(uname) == "Darwin" ]]; then # OSX
   . ${HOME}/.profile-osx
 elif [[ $(uname) == *BSD* ]]; then # FreeBSD