You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
635 B

6 years ago
#!/usr/bin/env bash
has() {
local verbose=false
if [[ $1 == '-v' ]]; then
verbose=true
shift
fi
for c in "$@"; do c="${c%% *}"
if ! command -v "$c" &> /dev/null; then
[[ "$verbose" == true ]] && err "$c not found"
return 1
fi
done
}
err() {
printf '\e[31m%s\e[0m\n' "$*" >&2
6 years ago
}
die() {
(( $# > 0 )) && err "$*"
6 years ago
exit 1
}
fzf() {
command fzf --ansi --inline-info "$@"
}
6 years ago
has -v nmcli fzf || die
network=$(nmcli --color yes device wifi | fzf --nth=2 --header-lines=1 | sed -r 's/^\s*\*?\s*//; s/\s*(Ad-Hoc|Infra).*//')
6 years ago
[[ -z "$network" ]] && exit
nmcli -a device wifi connect "$network"