Browse Source

Add/update docstrings to Bash interactive mode functions

Alois Mahdal 9 years ago
parent
commit
260f643a67
1 changed files with 46 additions and 3 deletions
  1. 46
    3
      dotfiles/bash/main.bashrc

+ 46
- 3
dotfiles/bash/main.bashrc View File

13
 ### '''' ###
13
 ### '''' ###
14
 
14
 
15
 git() {
15
 git() {
16
+    #
17
+    # /usr/bin/git wrapper just to disable dangerous commands
18
+    #
19
+    # In particular, `git-am` is a a close typo of my favorite
20
+    # aliases `ap` (`git-add --patch`) and `cm` (`git-commit`)
21
+    # but it's dangerous to call by accident as it destroys
22
+    # workdir changes.
23
+    #
16
     if grep -Fwqse "$1" "$GIT_DISABLED_COMMANDS"; then
24
     if grep -Fwqse "$1" "$GIT_DISABLED_COMMANDS"; then
17
         echo "You don't want this." >&2
25
         echo "You don't want this." >&2
18
         return 1
26
         return 1
22
 }
30
 }
23
 
31
 
24
 grepr() {
32
 grepr() {
33
+    #
34
+    # Grep recursively, keeping numbers and ignoring common dirs
35
+    #
36
+    # Number one tool for refactoring!
37
+    #
25
     local p=$1; shift
38
     local p=$1; shift
26
     grep --color -n --exclude-dir=".git" -e "$p" -r "$@"
39
     grep --color -n --exclude-dir=".git" -e "$p" -r "$@"
27
 }
40
 }
28
 
41
 
29
 greph() {
42
 greph() {
43
+    #
44
+    # Grep through bash history
45
+    #
30
     history | sed 's/^  *//; s/  / /' | cut -d' ' -f2- | grep "$@"
46
     history | sed 's/^  *//; s/  / /' | cut -d' ' -f2- | grep "$@"
31
 }
47
 }
32
 
48
 
33
 gitcd() {
49
 gitcd() {
50
+    #
51
+    # Deep in git repo, cd to the git root
52
+    #
34
     cd "$(git rev-parse --show-toplevel)"
53
     cd "$(git rev-parse --show-toplevel)"
35
 }
54
 }
36
 
55
 
37
 clsz() {
56
 clsz() {
57
+    #
58
+    # Clear screen and move the prompt to bottom
59
+    #
38
     tput clear; tput cup "$(tput lines)" 0
60
     tput clear; tput cup "$(tput lines)" 0
39
 }
61
 }
40
 
62
 
41
 bcdiff() {
63
 bcdiff() {
64
+    #
65
+    # Call bcompare only if objects actually differ
66
+    #
42
     test $# -eq 2 && diff "$@" >/dev/null && return
67
     test $# -eq 2 && diff "$@" >/dev/null && return
43
     bcompare "$@" &
68
     bcompare "$@" &
44
 }
69
 }
45
 
70
 
46
 vims() {
71
 vims() {
47
-    # 2015-07-10 06:10:48.603953758 +0200 ~/TODO.todo
72
+    #
73
+    # Show "abandoned" Vim .swp files in a nice table
74
+    #
75
+    # Call this after crash or poweroff to get back and recover
76
+    # files open before the fact.  Example:
77
+    #
78
+    #     2015-07-10 06:10:48.603953758 +0200 ~/TODO.todo
79
+    #
80
+    # Depends on .swp settings defined in my mydots repo.
81
+    #
48
     local swap="$HOME/.local/share/vim/swap"
82
     local swap="$HOME/.local/share/vim/swap"
49
     find "$swap" -type f -print0 \
83
     find "$swap" -type f -print0 \
50
       | xargs -0 -r stat -c "%y %n" \
84
       | xargs -0 -r stat -c "%y %n" \
60
 }
94
 }
61
 
95
 
62
 xod() {
96
 xod() {
63
-    # dump xo in a file named $1 somewhere in /tmp; echo the path
97
+    #
98
+    # Like mktemp but get the content from clipboard
99
+    #
100
+    # Dump xo in a file named $1 somewhere in /tmp; echo the path
64
     # usage: scp $(xod useful_name.txt) eg:some/shared/place
101
     # usage: scp $(xod useful_name.txt) eg:some/shared/place
65
     # instead of xo>useful_name.txt; scp useful_name.txt eg:some/shared/place; rm useful_name.txt
102
     # instead of xo>useful_name.txt; scp useful_name.txt eg:some/shared/place; rm useful_name.txt
103
+    #
66
     local name="${1:-clipboard_dump.txt}"
104
     local name="${1:-clipboard_dump.txt}"
67
     local tmp=$(mktemp -d -t "xod.XXXXXXXX")
105
     local tmp=$(mktemp -d -t "xod.XXXXXXXX")
68
     xclip -o > "$tmp/$name"
106
     xclip -o > "$tmp/$name"
70
 }
108
 }
71
 
109
 
72
 xood() {
110
 xood() {
73
-    # just like xod() but using xoo
111
+    #
112
+    # Just like xod() but using xoo (i.e. 'clipboard' clipboard)
113
+    #
74
     local name="${1:-clipboard_dump.txt}"
114
     local name="${1:-clipboard_dump.txt}"
75
     local tmp=$(mktemp -d -t "xood.XXXXXXXX")
115
     local tmp=$(mktemp -d -t "xood.XXXXXXXX")
76
     xclip -selection clipboard -o > "$tmp/$name"
116
     xclip -selection clipboard -o > "$tmp/$name"
78
 }
118
 }
79
 
119
 
80
 yum_hasbin() {
120
 yum_hasbin() {
121
+    #
122
+    # Ask yum who has bin $1 (and make the output actually readable)
123
+    #
81
     local bname
124
     local bname
82
     for bname in "$@";
125
     for bname in "$@";
83
     do
126
     do