Browse Source

bin(and): Improves adb wrapper script

main
creton32 6 days ago
parent
commit
8be08929e1
  1. 66
      bin/.local/bin/and

66
bin/.local/bin/and

@ -9,22 +9,64 @@ list() {
reset() {
notify-send "adb" "Restarting adb server..."
doas adb kill-server && doas adb start-server
adb kill-server && adb start-server
}
# Wifi setup for Android 10 or lower
wifi_setup() {
if adb devices | awk 'FNR==2 {print $1}'; then
adb tcpip 5555
local ip="$(adb shell su -c ifconfig |\
sed -n '/wlan0/,+1s/.*addr:\(.*\)[[:space:]][[:space:]]B.*/\1/p')"
[ -n "$ip" ] && adb connect "$ip"
setup_wireless () {
if adb devices | awk 'FNR==2 {print $1}' > /dev/null; then
local ip="$(adb shell su -c ifconfig | sed -n '/wlan0/,+1s/.*addr:\(.*\)[[:space:]][[:space:]]B.*/\1/p')"
(adb tcpip 5555 && [ -n "$ip" ]) && adb connect "$ip"
fi
}
#transfer() {
# Use FZF to transfer between devices
#}
find_remote () {
local path=${2:-Download}
case "$1" in
-f|--file) adb shell find /sdcard/"$path" -type f | fzf --prompt=" " --tiebreak=index ;;
-d|--dir) adb shell find /sdcard/"$path" -type d | fzf --prompt=" " --tiebreak=index ;;
*) adb shell find /sdcard/"$path" | fzf ;;
esac
}
find_local () {
case "$1" in
-f|--file)
fd -t f --follow --hidden . $HOME | \
proximity-sort $PWD 2>/dev/null | \
fzf --prompt=" " --tiebreak=index \
--preview 'bat --style="auto" --color=always {}'
;;
-d|--directory)
fd -t d --follow --hidden --exclude ".git" . $HOME | \
proximity-sort $PWD 2>/dev/null | \
fzf --prompt=" " --tiebreak=index \
--preview 'lsd -A --color always --icon always --group-dirs first {}'
;;
*)
fd --follow --hidden . $HOME | \
proximity-sort $PWD 2>/dev/null | \
fzf --tiebreak=index
;;
esac
}
transfer () {
case "$1" in
--push)
local local_file=$(find_local -f)
local remote_dir=$(find_remote -d)
([ -f $local_file ] && [ ! -z $remote_dir ]) && adb push $local_file $remote_dir
;;
--pull)
local remote_file=$(find_remote -f)
local local_dir=$(find_local -d)
([ ! -z remote_file ] && [ -d $local_dir ]) && adb pull $remote_file $local_dir
;;
esac
([ -n "$remote_file" ] && [ -d "$local_dir" ]) && adb pull "$remote_file" "$local_dir"
}
packages() {
case "$1" in
@ -60,6 +102,8 @@ single_user_setup() {
case "$1" in
-l|--list) shift && list "$@" ;;
-w|--wifi) wifi_setup ;;
-w|--wifi) setup_wireless ;;
-p|--packages) packages ;;
-r|--reset) reset ;;
-t|--mv) shift && transfer "$@" ;;
esac
Loading…
Cancel
Save