summaryrefslogtreecommitdiff
path: root/lib/functions.zsh
diff options
context:
space:
mode:
Diffstat (limited to 'lib/functions.zsh')
-rw-r--r--lib/functions.zsh45
1 files changed, 38 insertions, 7 deletions
diff --git a/lib/functions.zsh b/lib/functions.zsh
index 678e29ce7..73b491a59 100644
--- a/lib/functions.zsh
+++ b/lib/functions.zsh
@@ -1,5 +1,7 @@
function zsh_stats() {
- fc -l 1 | awk '{CMD[$2]++;count++;}END { for (a in CMD)print CMD[a] " " CMD[a]/count*100 "% " a;}' | grep -v "./" | column -c3 -s " " -t | sort -nr | nl | head -n20
+ fc -l 1 \
+ | awk '{ CMD[$2]++; count++; } END { for (a in CMD) print CMD[a] " " CMD[a]*100/count "% " a }' \
+ | grep -v "./" | sort -nr | head -20 | column -c3 -s " " -t | nl
}
function uninstall_oh_my_zsh() {
@@ -7,12 +9,8 @@ function uninstall_oh_my_zsh() {
}
function upgrade_oh_my_zsh() {
- env ZSH="$ZSH" sh "$ZSH/tools/upgrade.sh"
- command rm -rf "$ZSH/log/update.lock"
-}
-
-function take() {
- mkdir -p $@ && cd ${@:$#}
+ echo >&2 "${fg[yellow]}Note: \`$0\` is deprecated. Use \`omz update\` instead.$reset_color"
+ omz update
}
function open_command() {
@@ -35,6 +33,38 @@ function open_command() {
${=open_cmd} "$@" &>/dev/null
}
+# take functions
+
+# mkcd is equivalent to takedir
+function mkcd takedir() {
+ mkdir -p $@ && cd ${@:$#}
+}
+
+function takeurl() {
+ local data thedir
+ data="$(mktemp)"
+ curl -L "$1" > "$data"
+ tar xf "$data"
+ thedir="$(tar tf "$data" | head -1)"
+ rm "$data"
+ cd "$thedir"
+}
+
+function takegit() {
+ git clone "$1"
+ cd "$(basename ${1%%.git})"
+}
+
+function take() {
+ if [[ $1 =~ ^(https?|ftp).*\.tar\.(gz|bz2|xz)$ ]]; then
+ takeurl "$1"
+ elif [[ $1 =~ ^([A-Za-z0-9]\+@|https?|git|ssh|ftps?|rsync).*\.git/?$ ]]; then
+ takegit "$1"
+ else
+ takedir "$@"
+ fi
+}
+
#
# Get the value of an alias.
#
@@ -123,6 +153,7 @@ zmodload zsh/langinfo
# -P causes spaces to be encoded as '%20' instead of '+'
function omz_urlencode() {
emulate -L zsh
+ local -a opts
zparseopts -D -E -a opts r m P
local in_str=$1