Selaa lähdekoodia

Add/update docstrings to Bash interactive mode functions

Alois Mahdal 9 vuotta sitten
vanhempi
commit
260f643a67
1 muutettua tiedostoa jossa 46 lisäystä ja 3 poistoa
  1. 46
    3
      dotfiles/bash/main.bashrc

+ 46
- 3
dotfiles/bash/main.bashrc Näytä tiedosto

@@ -13,6 +13,14 @@ test -f /usr/share/git-core/contrib/completion/git-prompt.sh \
13 13
 ### '''' ###
14 14
 
15 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 24
     if grep -Fwqse "$1" "$GIT_DISABLED_COMMANDS"; then
17 25
         echo "You don't want this." >&2
18 26
         return 1
@@ -22,29 +30,55 @@ git() {
22 30
 }
23 31
 
24 32
 grepr() {
33
+    #
34
+    # Grep recursively, keeping numbers and ignoring common dirs
35
+    #
36
+    # Number one tool for refactoring!
37
+    #
25 38
     local p=$1; shift
26 39
     grep --color -n --exclude-dir=".git" -e "$p" -r "$@"
27 40
 }
28 41
 
29 42
 greph() {
43
+    #
44
+    # Grep through bash history
45
+    #
30 46
     history | sed 's/^  *//; s/  / /' | cut -d' ' -f2- | grep "$@"
31 47
 }
32 48
 
33 49
 gitcd() {
50
+    #
51
+    # Deep in git repo, cd to the git root
52
+    #
34 53
     cd "$(git rev-parse --show-toplevel)"
35 54
 }
36 55
 
37 56
 clsz() {
57
+    #
58
+    # Clear screen and move the prompt to bottom
59
+    #
38 60
     tput clear; tput cup "$(tput lines)" 0
39 61
 }
40 62
 
41 63
 bcdiff() {
64
+    #
65
+    # Call bcompare only if objects actually differ
66
+    #
42 67
     test $# -eq 2 && diff "$@" >/dev/null && return
43 68
     bcompare "$@" &
44 69
 }
45 70
 
46 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 82
     local swap="$HOME/.local/share/vim/swap"
49 83
     find "$swap" -type f -print0 \
50 84
       | xargs -0 -r stat -c "%y %n" \
@@ -60,9 +94,13 @@ vims() {
60 94
 }
61 95
 
62 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 101
     # usage: scp $(xod useful_name.txt) eg:some/shared/place
65 102
     # instead of xo>useful_name.txt; scp useful_name.txt eg:some/shared/place; rm useful_name.txt
103
+    #
66 104
     local name="${1:-clipboard_dump.txt}"
67 105
     local tmp=$(mktemp -d -t "xod.XXXXXXXX")
68 106
     xclip -o > "$tmp/$name"
@@ -70,7 +108,9 @@ xod() {
70 108
 }
71 109
 
72 110
 xood() {
73
-    # just like xod() but using xoo
111
+    #
112
+    # Just like xod() but using xoo (i.e. 'clipboard' clipboard)
113
+    #
74 114
     local name="${1:-clipboard_dump.txt}"
75 115
     local tmp=$(mktemp -d -t "xood.XXXXXXXX")
76 116
     xclip -selection clipboard -o > "$tmp/$name"
@@ -78,6 +118,9 @@ xood() {
78 118
 }
79 119
 
80 120
 yum_hasbin() {
121
+    #
122
+    # Ask yum who has bin $1 (and make the output actually readable)
123
+    #
81 124
     local bname
82 125
     for bname in "$@";
83 126
     do