-
Notifications
You must be signed in to change notification settings - Fork 5
/
EasierMinicom.sh
executable file
·55 lines (45 loc) · 1.31 KB
/
EasierMinicom.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
com() {
local ports_USB ports_ACM ports datename dev devs dev_count
ports_USB=$(ls /dev/ttyUSB* 2>null | xargs -I {} basename {})
ports_ACM=$(ls /dev/ttyACM* 2>null | xargs -I {} basename {})
ports="$ports_USB $ports_ACM"
#check lock
devs=""
dev_count=0
for dev in ${ports};
do
! ls /run/lock/*"${dev}"* &> /dev/null && { devs+="${dev} ";((dev_count++)); }
done;
[ -z "$devs" ] && echo "No Unlock Devices" && return 0;
datename=$(date +%Y%m%d-%H%M%S)
if [ $dev_count -eq 1 ]; then
dev=$devs
else
#select dev to open
echo "Please select one device: (Ctrl+C to abort)"
select dev in $devs;do
if [ "$dev" ]; then
echo "You select the '$dev'"
break
else
echo "Invaild selection"
fi
done
fi
out="/tmp/$(basename ${dev}).$datename.log"
keep_dir="${HOME}/minicom_keep"
minicom -D "/dev/$dev" -C "${out}" "$@"
[ -f "${out}" ] && {
echo log : "${out}"
read -p "Keep it? [y|N]: " keep;
[ "${keep}" = 'Y' -o "${keep}" = 'y' ] && {
read -p "Enter file name > " keep_file_name
[ x"$keep_file_name" = x"" ] && keep_file_name=$(basename "${out}")
mkdir -p "$keep_dir"
cp "${out}" "${keep_dir}/$keep_file_name"
echo "saved in $keep_dir/$keep_file_name"
}
}
read -p "Vim it? [y|N]: " edit_vim;
[ "${edit_vim}" = 'Y' -o "${edit_vim}" = 'y' ] && vim "${out}"
}