3 # need to set these shell options before they are relied upon when bash parses the big { ... } block later down.
5 shopt -s expand_aliases
6 # aliases in non-interactive bash script are not evaluated in the same scope where they are defined,
7 # but they are in the big { ... } block below.
8 alias set_site
='if [ -z "${site:-}" ]; then set_site_func "${1:-}"; shift; fi;'
15 .
/usr
/lib
/tool
/bash-utils
16 .
/usr
/lib
/tool
/ansi-codes
22 local i stack_size
=${#FUNCNAME[@]}
23 for (( i
=1; i
<stack_size
; i
++ )); do
24 local func
="${FUNCNAME[$i]}"
25 [[ $func = "" ]] && func
=MAIN
26 local linen
="${BASH_LINENO[$(( i - 1 ))]}"
27 local src
="${BASH_SOURCE[$i]}"
28 [[ "$src" = "" ]] && src
=non_file_source
30 echo -n "$ANSI_bold$ANSI_fg_black"
31 echo " function: $func"
32 echo " file: $src (line $linen)"
35 local line_number_text_sep
='| '
36 nl -ba -w ${#linen} -s " $line_number_text_sep" "$src" |
grep -C 2 -E "^\s*$linen " |\
38 sed -e "s/^\(\s*$linen\) \(.\{${#line_number_text_sep}\}\)\(.*\)/\1-\2$ANSI_italic\3$ANSI_normal/" |\
39 sd
'^' "$ANSI_bold$ANSI_fg_black" | sd
'$' "$ANSI_reset"
43 trap 'print_traceback >&2' ERR
50 errx
1 "Enter site name or directory!"
53 site
=`basename "$param"`
61 [[ $1 =~ password|key|cvc|secret|pin
]]
67 if type copyq
1>/dev
/null
2>&1 && is_secret
"$prop"
69 copyq_monitoring
=`copyq monitoring`
70 if [ "$copyq_monitoring" = true
]
75 if [ "$copyq_monitoring" = true
]
80 xclip
-i -selection clipboard
89 if [ "${1:-}" = site
]
107 GLOBIGNORE
=${GLOBIGNORE:-}${GLOBIGNORE:+:}".:..:.[!/.]*:..[!/]*:-*"
116 if in_list reveal-secrets
"${options[@]}"
119 elif in_list hash-secrets
"${options[@]}"
121 hash=`cat "$file" | md5sum | cut -c 1-32`
122 echo "$file$TAB$hash$TAB""hash-algo=md5"
125 echo "$file"$
'\t'"*****"
130 grep .
"$file" | prefixlines
"$file"$
'\t'
137 cred dump
"$parent" "${options[@]}"
143 cat "$basedir/$site/PASSWORD"
146 find -L "$basedir" -path "$basedir/${1:-}*" -type d
-printf "%P\n"
150 prop
=${1:?'enter property name!'}
158 warnx
"$prop is a secret."
159 warnx
"enter 'cred [...] prop [...] $prop show' explicitely, or"
160 warnx
"more preferably 'cred [...] prop [...] $prop clip' to copy to the clipboard!"
163 cat "$basedir/$site/$prop"
167 cat "$basedir/$site/$prop" | do_clip
"$prop"
170 elif [ "$subcmd" = prop
]
176 mkdir
-p "$basedir/$site"
177 printf '%s' "$val" > "$basedir/$site/$prop"
180 mkdir
-p "$basedir/$site"
181 "${EDITOR:-$VISUAL}" "$basedir/$site/$prop"
186 read -s -p "$prop: " -e val
188 read -p "$prop: " -e val
190 printf '%s' "$val" > "$basedir/$site/$prop"
193 rm "$basedir/$site/$prop"
196 cat "$basedir/$site/$prop"
199 cat "$basedir/$site/$prop" | do_clip
"$prop"
202 false
"invalid argument"
214 val
=`cat "$basedir/$site/$prop"`
215 strings="$strings$val"$
'\t'
217 xdotool key Alt
+Tab
type "$strings"
219 errx
1 "Enter property names in order to fill the form on the window brought to focus by Alt+Tab."
224 find "$basedir/$site" -type f
-printf "%P\n"
228 newpwd
=$
(pwgen
-y 8 1)$
(pwgen
-y 8 1)
230 pwdfile
=$basedir/$site/PASSWORD
231 mkdir
-p "$basedir/$site"
234 cur_pwd
=`cat "$pwdfile"`
235 atime
=`stat -c %x "$pwdfile"`
236 now
=`date +'%F %T.%N %z'`
237 echo "$atime $now $cur_pwd" >> "$basedir/$site/OLDPASSWORDS"
239 printf '%s' "$newpwd" > "$pwdfile"
243 _autocomplete_cred() {
245 local curr_word=${COMP_WORDS[$COMP_CWORD]}
246 local prev_word=${COMP_WORDS[$[COMP_CWORD - 1]]}
247 local site_subcmds="list-sites dump generate-password list-props prop clip fill-form"
251 compreply="compscript site $site_subcmds"
254 local site=$curr_word; site=${site/#'~/'/$HOME/}
255 compreply=`cred list-sites "$site"`
258 local subcmd=${COMP_WORDS[1]}
259 local site=${COMP_WORDS[2]}; site=${site/#'~/'/$HOME/}
260 local cword_idx=$COMP_CWORD
261 if [ "$subcmd" = site ]
263 if [ $COMP_CWORD = 3 ]
265 compreply="$site_subcmds"
267 subcmd=${COMP_WORDS[3]}
275 compreply=`cred list-props "$site"`
278 compreply="set edit read del show clip"
283 compreply=`cred list-props "$site"`
288 compreply="reveal-secrets mask-secrets hash-secrets"
294 COMPREPLY=($(compgen -W "$compreply" -- "${COMP_WORDS[$COMP_CWORD]}"))
297 complete -F _autocomplete_cred cred
298 # use this in your bash session by eg: eval "$(cred compscript)"
302 warnx
'Use tab-completion!'
303 warnx
'Example: eval "$(cred compscript)"'