-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathfunctions
100 lines (82 loc) · 2.08 KB
/
functions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
function psgrep() {
ps auxf | grep -v grep | grep "$@" -i
}
function fname() {
find . -iname "*$@*"
}
function remove_lines_from() {
# Removes lines from $1 if they appear in $2
grep -F -x -v -f $2 $1
}
function mkcd() {
mkdir $1 && cd $1
}
# Easily create a temp directory and cd into it for quick experiments
function t {
cd $(mktemp -d /tmp/$1.XXXX)
}
# Functions for opening various things from the command line
############################################################
search_string() {
search=""
for term in "$@"; do
search="$search%20$term"
done
echo "$search"
}
function goo() {
search_string "$@"
open "http://www.google.com/search?q=$(search_string "$@")"
}
function duc() {
search_string "$@"
open "http://www.duckduckgo.com?q=$(search_string "$@")"
}
function open_ticket() {
if [ -n "$BASE_TICKET_URL" ]; then
open "$BASE_TICKET_URL$1"
else
echo "BASE_TICKET_URL is not set"
return 1
fi
}
# A simple debug function that can be used inside shell scripts to pause
# execution and allow for inspection of the environment and execution of
# commands.
# Example usage in a script:
# #! /usr/bin/env bash
# # Load the debug function
# source scripts/functions/debug.sh
#
# ...
#
# # Then use it somewhere
# foobar() {
# debug # Now I can inspect the variables that were passed into foobar
# }
function debug
{
echo "#############| Entering DEBUG mode |####################";
local cmd=""
while [[ $cmd != "exit" ]]; do
# read -p is broken on OSX, so I just print the prompt manually
echo -n "> "
read cmd
case $cmd in
vars ) ( set -o posix ; set );;
exit ) ;;
* ) eval "$cmd";;
esac
done
echo "#############| End of DEBUG mode |####################";
}
# From https://stackoverflow.com/questions/16311688/bash-convert-epoch-to-date-showing-wrong-time
epoch_to_timestamp() {
epoch="${1:-}"
if [ "${#epoch}" = 13 ]; then
date -r "$((epoch/1000))"
else
date -r "$epoch"
fi
unset epoch
}