-
Notifications
You must be signed in to change notification settings - Fork 0
/
.functions
94 lines (82 loc) · 2.2 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
#!/usr/bin/env bash
# Create a new directory and enter it
function mk() {
mkdir -p "$@" && cd "$@"
}
function cdf () {
# cd into whatever is the forefront Finder window.
local path=$(osascript -e 'tell app "Finder" to POSIX path of (insertion location as alias)')
echo "$path"
cd "$path"
}
function fh() {
eval $( ([ -n "$ZSH_NAME" ] && fc -l 1 || history) | fzf +s --tac | sed 's/ *[0-9]* *//')
}
# From Dan Ryan's blog - http://danryan.co/using-antigen-for-zsh.html
function man() {
# Shows pretty `man` page.
env \
LESS_TERMCAP_mb=$(printf "\e[1;31m") \
LESS_TERMCAP_md=$(printf "\e[1;31m") \
LESS_TERMCAP_me=$(printf "\e[0m") \
LESS_TERMCAP_se=$(printf "\e[0m") \
LESS_TERMCAP_so=$(printf "\e[1;44;33m") \
LESS_TERMCAP_ue=$(printf "\e[0m") \
LESS_TERMCAP_us=$(printf "\e[1;32m") \
man "$@"
}
# Open man page as PDF
function manpdf() {
man -t "${1}" | open -f -a /Applications/Preview.app/
}
# Determine size of a file or total size of a directory
function fs() {
if du -b /dev/null > /dev/null 2>&1; then
local arg=-sbh;
else
local arg=-sh;
fi
if [[ -n "$@" ]]; then
du $arg -- "$@";
else
du $arg .[^.]* ./*;
fi;
}
# Change directories and view the contents at the same time
function cl() {
DIR="$*";
# if no DIR given, go home
if [ $# -lt 1 ]; then
DIR=$HOME;
fi;
builtin cd "${DIR}" && \
# use your preferred ls command
ls -F --color=auto
}
# Sets the window title nicely no matter where you are
function title() {
# escape '%' chars in $1, make nonprintables visible
a=${(V)1//\%/\%\%}
# Truncate command, and join lines.
a=$(print -Pn "%40>...>$a" | tr -d "\n")
case $TERM in
screen)
print -Pn "\ek$a:$3\e\\" # screen title (in ^A")
;;
xterm*|rxvt)
print -Pn "\e]2;$2\a" # plain xterm title ($3 for pwd)
;;
esac
}
function loop_file() {
echo 'To Read a file line by line and execute commands use:\n'
echo ' for i in *.txt; do command "$i"; done'
echo ' OR'
echo ' while read line; do command "$line"; done < file.txt'
}
function kotlinr() {
timestamp=$(date +%s)
kotlinc $1 -include-runtime -d $timestamp_$1.jar
java -jar $timestamp_$1.jar
rm $timestamp_$1.jar
}