about summary refs log tree commit diff
path: root/functions
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2016-08-23T18·14-0400
committerWilliam Carroll <wpcarro@gmail.com>2016-08-23T18·14-0400
commitc836c5508134cee1aa004a83784ccef162c9603c (patch)
treef8b16d77aadbbf94bcebbf56a54ef099dcb0ecef /functions
parent342e7dbcd9fb6954be127b43a7850e4513ef8304 (diff)
parent337ba2e247963c80446bfaa14399344fca83c202 (diff)
Merge branch 'master' of https://github.com/wpcarro/pc_settings
Diffstat (limited to 'functions')
-rw-r--r--functions/git_functions.sh78
-rw-r--r--functions/history_functions.sh29
-rw-r--r--functions/index.sh52
-rw-r--r--functions/js_to_bash.sh29
-rw-r--r--functions/misc_functions.sh40
-rw-r--r--functions/vim_functions.sh29
6 files changed, 257 insertions, 0 deletions
diff --git a/functions/git_functions.sh b/functions/git_functions.sh
new file mode 100644
index 000000000000..6ed195a81253
--- /dev/null
+++ b/functions/git_functions.sh
@@ -0,0 +1,78 @@
+# output current branch to STDOUT
+function wgbranch {
+  cat ./.git/HEAD | perl -p -e 's/^ref:\srefs\/heads\/(.+)$/\1/g'
+}
+
+
+# output the stash ticket number to STDOUT
+function wgtix {
+  wgbranch | perl -p -e 's/(?:feature|bugfix|refactor)\/(\w+-\d+).+$/\1/'
+}
+
+
+# search for a git branch by ticket number
+# useful when combined with `wgcheckout`
+# e.g.
+# $ wgcheckout "$(wgfind 1045)"
+# checks-out feature/GDMX-1045 ...
+#
+# if the `TICKET_NO` cannot be found, it will return the current branch
+function wgfind {
+  TICKET_NO="$1"
+
+  BRANCHNAME=$(git branch | grep "$TICKET_NO" | perl -p -e 's/^\s*//')
+
+  if [ -z $BRANCHNAME ]; then
+    BRANCHNAME="$(wgbranch)"
+  fi
+
+  echo "$BRANCHNAME"
+}
+
+
+# wrapper fn for "git checkout" that exports previous branch to env
+function wgcheckout {
+  if [ -z $1 ]; then
+    branchname="develop"
+  else
+    branchname="$1"
+  fi
+
+  echo " -- wgcheckout -- "
+  echo "Storing branch \"$(wgbranch)\" in WGPREV ..."
+  export WGPREV="$(wgbranch)"
+  echo "Checking out \"$branchname\" ..."
+  echo
+  echo " -- git checkout -- "
+  git checkout "$branchname"
+  echo
+}
+
+
+# opens the current ticket-branch in web browser
+function wgjira {
+  base_url="https://jira.hugeinc.com/browse"
+  ticket=$(wgtix)
+
+  open "${base_url}/${ticket}"
+}
+
+
+# wgcheckout combined with a fuzzy search
+function wgfcheckout {
+  branchname=$(trim $(git branch | fzf))
+
+  [ ! -z "$branchname" ] && wgcheckout "$branchname" || return
+}
+
+
+# View an author's work within a specified date range. 
+function wgviewcommits {
+  author=$([ -z "$1" ] && echo "William Carroll" || echo "$1")
+  todays_date=$(date +'%Y-%m-%d')
+  date=$([ -z "$2" ] && echo "${todays_date}" || echo "$2")
+
+  git log --all --author="${author}" --after="${date} 00:00" \
+        --before="${date} 23:59"
+}
+
diff --git a/functions/history_functions.sh b/functions/history_functions.sh
new file mode 100644
index 000000000000..5f97884b1018
--- /dev/null
+++ b/functions/history_functions.sh
@@ -0,0 +1,29 @@
+#!/usr/bin/env bash
+
+
+HISTFILE=~/.zsh_history
+
+
+function wh_two_back {
+  command=$(history | tail -n 2 | head -n 1 | cut -c 8-)
+  echo -n $command
+}
+
+
+function wh_three_back {
+  command=$(history | tail -n 3 | head -n 1 | cut -c 8-)
+  echo -n "$command"
+}
+
+
+function wh_four_back {
+  command=$(history | tail -n 4 | head -n 1 | cut -c 8-)
+  echo -n "$command"
+}
+
+
+function wh_five_back {
+  command=$(history | tail -n 5 | head -n 1 | cut -c 8-)
+  echo -n "$command"
+}
+
diff --git a/functions/index.sh b/functions/index.sh
new file mode 100644
index 000000000000..ae73bed38f54
--- /dev/null
+++ b/functions/index.sh
@@ -0,0 +1,52 @@
+npms() {
+  clear;
+  npm start;
+}
+
+
+# custom js functions
+source $HOME/pc_settings/functions/js_to_bash.sh
+
+# custom git functions
+source $HOME/pc_settings/functions/git_functions.sh
+
+# custom bash helpers functions
+source $HOME/pc_settings/functions/misc_functions.sh
+
+# custom history functions for zle bindkey
+source $HOME/pc_settings/functions/history_functions.sh
+
+# custom functions to work with vim
+source $HOME/pc_settings/functions/vim_functions.sh
+
+# generates placeholder content for FE work
+function lorem {
+    text="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
+
+    echo $text
+}
+
+# generates lorem and adds to pasteboard
+function loremcp {
+    lorem | pbcopy
+}
+
+# searches all PATH directories for a keyword
+function wsearchpath {
+  echo $PATH | tr ':' '\n' | xargs -I {} find {} -type f -perm +111 -maxdepth 1 -name "*${1}*" -print | xargs basename
+}
+
+
+# tests an internet connection
+function is_online {
+  wget -q --spider "http://google.com"
+
+  if [ $? -eq 0 ]; then
+    echo "Online"
+    return 0
+  else
+    echo "Offline"
+    return 1
+  fi
+}
+
diff --git a/functions/js_to_bash.sh b/functions/js_to_bash.sh
new file mode 100644
index 000000000000..22a70a556077
--- /dev/null
+++ b/functions/js_to_bash.sh
@@ -0,0 +1,29 @@
+# js function syntax for bash
+
+function trimend {
+    LENGTH=${#1}
+    AMT=$2
+    TAKE=$((LENGTH-AMT))
+    echo $1 | cut "-c-$TAKE"
+}
+
+function trimfront {
+    TMP0=$(echo $1 | rev)
+    TMP1=$(trimend $TMP0 $2 | rev)
+    echo $TMP1
+}
+
+function length {
+    echo ${#1}
+}
+
+function slice {
+  start="$1"
+  end="$2"
+  string="$3"
+  echo "${string:${start}:${end}}"
+}
+
+function setInterval {
+  eval "while true; do $1; sleep $2; done"
+}
diff --git a/functions/misc_functions.sh b/functions/misc_functions.sh
new file mode 100644
index 000000000000..17c13d7a6ae9
--- /dev/null
+++ b/functions/misc_functions.sh
@@ -0,0 +1,40 @@
+# download files to /tmp directory
+function wdownload {
+  URL="$1"
+  FILENAME="$(basename $URL)"
+
+  wget -O /tmp/"$FILENAME" $URL >/dev/null && open /tmp && echo "Downloaded to: /tmp/$FILENAME" || echo "Error ..."
+}
+
+
+# spell checker
+function wspcheck {
+  if [ $# -ge 1 -a -f "$1" ] && input="$1" || input="-"
+  cat "$input" | tr '[:upper:]' '[:lower:]' | tr -cd '[:alpha:]_ \n' | tr -s ' ' '\n' | sort | comm -23 - ~/english_words.txt
+}
+
+
+# fuzzily search through dirs stack
+function wfd {
+  dir=$(dirname $(fzf)) && pushd "$dir" >/dev/null
+}
+
+
+# pushd into a directory on your dirs stack
+function wpushd {
+  dir="$(dirs | tr ' ' '\n' | fzf)" && pushd "$dir"
+}
+
+
+# trims leading and trailing whitespace
+function trim {
+  input="$1"
+
+  echo "${input//[[:blank:]]/}"
+}
+
+
+function wgreviewers {
+  echo "BJ Warshaw\nDaniel Wasilewski\nSean Sullivan\nCharles Morrissey\nRyan Balch\nZach Goldstein\nWilliam Anderson"
+}
+
diff --git a/functions/vim_functions.sh b/functions/vim_functions.sh
new file mode 100644
index 000000000000..63e01b534b18
--- /dev/null
+++ b/functions/vim_functions.sh
@@ -0,0 +1,29 @@
+#!/usr/bin/env bash
+
+# Easily search for strings within the files within the current directory.
+# Specify file extensions and directories to exclude to improve accuracy.
+# The file selected from fzf will be opened in vim.
+function vfzopen() {
+  echo -n "Search Term: "
+  read search_query
+  echo -n "Filename: "
+  read filetype
+  echo -n "Exclude Directory: "
+  read exclude_dir
+
+  if [ ! -z "$exclude_dirs" ]; then
+    filename=$(find . -type f -name "$filetype" | \
+       xargs grep -l "$search_query" | fzf)
+  else
+    filename=$(find . -type f -name "$filetype" -not -path "./${exclude_dir}/*" \
+       | xargs grep -l "$search_query" | fzf)
+  fi
+
+
+  if [ ! -z "$filename" ]; then
+    vim "$filename"
+    return 0
+  else
+    return 1
+  fi
+}