brossetti1
10/15/2017 - 5:19 PM

utilities

# Generic Utilities


using_port() {
  ps -p $(lsof -i:$1 -Fp | cut -c 2-)
}

most_used() {
  history | awk '{a[$4]++}END{for(i in a){print a[i] " " i}}' | sort -rn | head -20
}


echoRun() {
  START=$(date +%s)
  echo "> $1"
  eval time $1
  END=$(date +%s)
  DIFF=$(( $END - $START ))
  echo "It took $DIFF seconds"
}

sanitize() {
  echo $1 | tr ":  /."  "-" | tr -d ",'\""
}


# history grep tail
hgt() {
  fc -l 1 | grep -i --color=auto $1 | tail -n 40
}



funcs() {
  # With cheating by looking at the _functions completion function, I'm able to
  # answer your question:
  # 
  # The functions are stored in an associative array functions, so to get only the
  # funtion names (k flag for keys) in alphabetical order (o flag for ordering)

  # then use which <func_name> to see the definition of that function
  print -l ${(ok)functions}
}



marked() {
  if [[ -f $1 ]]; then 
    open -a marked.app $1 
    echo found file $1
  else
    open -a marked.app
    echo no file existing $1
  fi
}