]> arthur.barton.de Git - ax-zsh.git/blob - default_plugins/std_functions/std_functions.zshrc
ls: Add support for "lscolors.sh"
[ax-zsh.git] / default_plugins / std_functions / std_functions.zshrc
1 # AX-ZSH: Alex' Modular ZSH Configuration
2 # std_functions: Setup standard ("common") functions
3
4 function open_command() {
5         case $OSTYPE in
6                 darwin*)
7                         open "$@" || return 1
8                         ;;
9                 cygwin*)
10                         cygstart "$@" || return 1
11                         ;;
12                 linux*)
13                         if [[ -n "$DISPLAY" ]]; then
14                                 # X11
15                                 nohup xdg-open "$@" &>/dev/null || return 1
16                         else
17                                 xdg-open "$@" || return 1
18                         fi
19                         ;;
20                 *)
21                         return 2
22         esac
23         return 0
24 }
25
26 function take() {
27         if [[ $# -eq 0 ]]; then
28                 cd "$(mktemp -d)"
29                 pwd
30         else
31                 mkdir -p "$@" && cd "${@:$#}"
32         fi
33 }
34
35 function untake() {
36         pwd="${PWD}/"
37         subdir="${pwd##$TMPDIR}"
38         if [[ "${PWD%tmp.*}" = "${TMPDIR}" && -n "$subdir" ]]; then
39                 tmp_d="${TMPDIR}${subdir%%/*}"
40                 echo "$tmp_d"
41                 cd
42                 rm -fr "$@" "${tmp_d}"
43         else
44                 echo 'Sorry, not a temporarily taken directory!' >&2
45                 return 1
46         fi
47 }
48
49 function zsh_stats() {
50         fc -l 1 \
51         | awk '{CMD[$2]++;count++;}END { for (a in CMD)print CMD[a] " " CMD[a]/count*100 "% " a;}' \
52         | grep -v "./" | column -c3 -s " " -t | sort -nr | nl -w 3 -s ": " | head -n20
53 }