Skip to content

Instantly share code, notes, and snippets.

@for2ando
for2ando / ssh-agent-ctl.sh
Last active November 10, 2023 17:10
Syntax sugar for ssh-agent command
ssh-agent-ctl() {
local progname specfile sockconf
readonly progname="${FUNCNAME[0]}"
[ $# -le 0 ] && { echo "usage: $progname {start|stop|load|clean}"; return; }
readonly specfile=$HOME/.ssh/agent
readonly sockconf=$HOME/.ssh/config-agent
exist_process() { [ -n "$1" ] && kill -0 "$1" >/dev/null 2>&1; }
exist_socket() { [ -n "$1" -a -S "$1" ]; }
while true; do
@for2ando
for2ando / make-stock-recovery
Created July 1, 2017 13:54
Make stock recovery.img from boot (kernel) image on a Android device and several saved configuration file. Requires adb connection to the Android device.
#!/usr/bin/bash
progname=`basename "$0"`
usage="$progname check ConfDir
check if the current installed recovery is the stock recovery
which designated by the configuration.
$progname make ConfDir [Out]
make a stock recovery image file from the configuration
and the boot image on the phone.
ConfDir a directory includes install-recovery.sh and recovery-from-boot.p
Out file name for a recovery image made. [default=recovery.img]"
@for2ando
for2ando / adb-sendkey
Last active October 16, 2022 13:57
Automate key input to Android applications and system utilities using input command on any Android device via adb
#!/bin/bash
pnam=$(basename "$0")
usage="$pnam [-b] [-n] [-v] KeySequence
$pnam {-h|--help}
"
adb_shell_input_keyevent() {
$verbose && echo "adb shell input keyevent $1"
$dryrun || adb shell -n input keyevent $1
}
@for2ando
for2ando / make-password
Last active October 16, 2022 13:55
Generate easy-typable () password ramdomly.
#!/usr/bin/ruby -Ks
# -*- mode:ruby; -*-
require 'parsearg'
### constants
## character-classes
LETTERS = 'abcdefghijklmnopqrstuvwxyz0123456789'.unpack('c*')
LEFTYS = '1qaz2wsx3edc4rfv5tg'.unpack('c*')
RIGHTYS = 'p0lo9ki8mju7nhy6b'.unpack('c*')
@for2ando
for2ando / ipc
Last active October 16, 2022 13:53
Symtax sugar for ipconfig command of Windows.
#!/bin/sh
ipconfig /all | iconv -f sjis -t utf-8 | sed -n '/'"$1"':/,/^[^ \r\t]/p' | head -n -1
@for2ando
for2ando / getfilebk
Created July 1, 2017 14:21
Back up several configuration files from Android device via adb.
#!/bin/sh
adb shell ls /system || { echo $0:Please connect w/ adb.>&2; exit 2; }
for i in build.prop recovery-from-boot.p etc/recovery-resource.dat bin/install-recovery.sh; do
test -f $i && { echo $0: $i: exists. Please delete it and retry.>&2; exit 3; }
done
mkdir -p bin etc
adb pull /system/build.prop .
adb pull /system/recovery-from-boot.p .
adb pull /system/etc/recovery-resource.dat etc
adb pull /system/etc/install-recovery.cfg etc
@for2ando
for2ando / xcygstart
Last active March 19, 2019 10:14
Slightly extended cygstart command clone for cygwin (and expected for msys2).
#!/bin/bash
usage="$0 [Options] [NumberOfSkippingPathConvert] Command [Args]
Description:
call spacified command with spacified args which is replaced path-delimiter
character / to \.
Options:
-c with cmd.exe (Command is executed with 'cmd.exe /k')
-x (not implemented yet)
-s synchronize execution (wait a termination of Command)
-n dry run mode
@for2ando
for2ando / robocp
Last active October 18, 2022 10:07
Syntax sugar for robocopy command on Windows (typically for using on cygwin or msys2).
#/bin/bash
pname=$(basename "$0")
usage="usage: $pname ArgumentForRobocopy [...]
OPTIONS
ArgumentForRobocopy
same argument for robocopy, but a file path can includes unix style path,
and options for robocopy must begin '-' character instead of '/' character.
"
@for2ando
for2ando / backup-and-list
Created July 11, 2017 11:18
A shell script for backup and then make lists of backup files and write the list to files in source directories.
#!/bin/bash
LIST_FILE_NAME='BKLIST.txt'
LIST_CMD='ls -l -R'
pname=$(basename "$0")
usage="$pname [-ls DirGlobToMakeListFile] SourceDir DestDir
OPTIONS
SourceDir
A source directory of copying (not a miroring)
DestDir
A destination directory of copying
@for2ando
for2ando / get-android-app-name
Last active June 16, 2018 11:54
Get Android Application's pet name and print for given application IDs.
#!/bin/bash
pname=$(basename "$0")
usage="$pname [-h|--help|-inpqw] {AppId [...]|-}
FEATURES
print an application name of an Android application that designated with
AppId.
OPTIONS
-h --help
print this help message.
-i