plugins/base: `pickfrom()`
parent
c975f31899
commit
c8ed9a9da8
|
|
@ -44,9 +44,11 @@ function pickfrom() {
|
||||||
param '1: filename'
|
param '1: filename'
|
||||||
example '$ pickfrom /usr/share/dict/words'
|
example '$ pickfrom /usr/share/dict/words'
|
||||||
group 'base'
|
group 'base'
|
||||||
local file=$1
|
local file=${1:-}
|
||||||
[[ -z "$file" ]] && reference $FUNCNAME && return
|
if [[ ! -r "$file" ]]; then
|
||||||
local -i length="$(wc -l "$file")"
|
reference "${FUNCNAME[0]}" && return
|
||||||
|
fi
|
||||||
|
local -i length="$(wc -l < "$file")" n=0
|
||||||
n=$(( RANDOM * length / 32768 + 1 ))
|
n=$(( RANDOM * length / 32768 + 1 ))
|
||||||
head -n $n "$file" | tail -1
|
head -n $n "$file" | tail -1
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue