Skip to content

Instantly share code, notes, and snippets.

@felipeska
Forked from eveliotc/android-select-device
Last active August 29, 2015 14:12
Show Gist options
  • Save felipeska/cabd14dc02a370c0d629 to your computer and use it in GitHub Desktop.
Save felipeska/cabd14dc02a370c0d629 to your computer and use it in GitHub Desktop.
# This should be included from your ~/.zshrc or ~/.bash_profile like
# source ~/some/path/common.sh
# Requires to be preinstalled for certain functions/aliases: git, ack, ditto, imagemagick, jq, icdiff
# Aliases
alias g='git'
alias status='git status'
alias cutediff='git icdiff'
alias cutelog="git log --all --graph --pretty=format:'%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative"
alias log='git log'
alias newfeature='git checkout -b'
alias develop='git checkout develop'
alias master='git checkout master'
alias amend='git commit --amend'
alias commit='git commit -m'
alias add-all='git add .'
alias rebase='git rebase'
alias deletelocalbranch='git branch -d'
alias changebranch='git checkout'
alias cdapp='cd '$MAIN_APP_PATH
alias resditto='ditto -V res '$MAIN_APP_PATH'/app/res'
alias cdlibrary='cd '$MAIN_LIB_PATH
# requires my-adb script below
alias adb='my-adb'
alias gc='./gradlew clean'
alias gcad='./gradlew clean assembleDebug'
alias gcar='./gradlew clean assembleRelease'
myforkstr() {
git remote show -n $GITHUB_USERNAME | ack Push | ack -o '/(.*?).git' | sed -e '1s/^.//' -e 's/\.git$//g'
}
currentbranchstr()
{
git rev-parse --abbrev-ref HEAD;
}
pullrequest () {
currentBranch=`currentbranchstr`;
echo "Pushing to "$GITHUB_USERNAME"/"$currentBranch
git push $GITHUB_USERNAME $currentBranch
myfork=`myforkstr`;
prUrl="https://github.com/eveliotc/"$myfork"/pull/new/"$currentBranch
echo "Opening in browser "$prUrl
open $prUrl
}
finishfeature () {
currentBranch=`currentbranchstr`;
develop
echo "Fetching "$MAIN_REMOTE_NAME
git fetch $MAIN_REMOTE_NAME
echo "Pulling "$MAIN_REMOTE_NAME" develop"
git pull $MAIN_REMOTE_NAME develop
echo "Removing feature branch "$currentBranch
deletelocalbranch $currentBranch
echo "Pushing to "$GITHUB_USERNAME" develop"
git push $GITHUB_USERNAME develop
}
function gi() { curl http://www.gitignore.io/api/$@ ;}
alias gitignore='gi'
# adb stuff
adb-screenshot () {
if [[ -z "$1" ]]; then
echo "You must provide an image file path.";
return 1;
fi
adb shell screencap -p | perl -pe 's/\x0D\x0A/\x0A/g' > "$1"
}
# requests
get () {
if [[ -z "$1" ]]; then
echo "You must provide an URL to GET.";
return 1;
fi
curl -s "$1" | jq '.'
}
alias GET='get'
# resources
rmresource () {
if [[ -z "$1" ]]; then
echo "You must provide a resource id, name or pattern.";
return 1;
fi
RESID="$1"
RESDIR="res";
if [[ -d "$2" ]]; then
RESDIR="$2";
fi
if [[ ! -d "$RESDIR" ]]; then
echo "res directory not found.";
return 1;
fi
echo "Using resource directory "$RESDIR;
echo "Finding resources like "$RESID;
for item in $( find $RESDIR -type f -maxdepth 2 -iname "*"$RESID"*" ); do
rm -iv $item
done
}
# navigation
# Up from http://daniele.livejournal.com/76011.html
function up()
{
dir=""
if [ -z "$1" ]; then
dir=..
elif [[ $1 =~ ^[0-9]+$ ]]; then
x=0
while [ $x -lt ${1:-1} ]; do
dir=${dir}../
x=$(($x+1))
done
else
dir=${PWD%/$1/*}/$1
fi
cd "$dir";
}
function upstr()
{
echo "$(up "$1" && pwd)";
}
#!/usr/bin/python
import sys, subprocess, os
APKS_PATH="/data/app/"
UNZIP_DIR_SUFFIX="-unzip/"
def shell(args):
return subprocess.Popen(args, stdout=subprocess.PIPE, universal_newlines=True).communicate()[0]
def listPackages():
lines = shell(["adb", "shell", "su", "-c", "ls " + APKS_PATH]).split(os.linesep)
result = []
for line in lines:
if "apk" in line:
result.append(line)
return result
def listPackagesCli():
print "List of packages installed"
for package in listPackages():
print package.replace(".apk", "").split("-")[0]
def pull(packageFile):
print "Pulling " + packageFile + "..."
print shell(["adb", "pull", APKS_PATH + packageFile])
def decompile(packageFile):
print "Decompiling " + packageFile + "..."
print shell(["apktool", "d", packageFile])
def getUnzipDir(packageFile):
return packageFile + UNZIP_DIR_SUFFIX;
def unzip(packageFile):
print "Unzipping " + packageFile + "..."
targetDir = getUnzipDir(packageFile)
os.makedirs(targetDir)
print shell(["unzip", packageFile, "-d", targetDir])
def undex(packageFile):
print "Undexing " + packageFile + "..."
print shell(["dex2jar.sh", packageFile])
def all(package, dir):
print "Decompiling " + package + " in " + dir
os.makedirs(dir)
os.chdir(dir)
decompiled = 0
for packageFile in listPackages():
if package in packageFile:
pull(packageFile)
decompile(packageFile)
unzip(packageFile)
undex(packageFile)
decompiled += 1
if (decompiled == 0):
print "No package " + package + " found."
else:
shell(["cd", "'" + dir + "'"])
shell(["open", "."])
print "Done :D"
def main():
argLen = len(sys.argv)
if argLen < 2:
listPackagesCli()
return 1
package = sys.argv[1]
if argLen == 2:
dir = package
else:
dir = sys.argv[2]
all(package, dir)
if __name__ == "__main__":
sys.exit(main())
#!/bin/zsh
# Requires ImageMagick
DPI="$1"
if [[ -z "$1" ]]; then
DPI='xhdpi'
echo "$(tput setaf 3)WARN: Assuming $DPI$(tput sgr0)"
fi
typeset -A densities
densities=( "xxxhdpi" 4.0 "xxhdpi" 3.0 "xhdpi" 2.0 "hdpi" 1.5 "mdpi" 1.0 )
ratio=$densities[$DPI]
if [[ -z "$ratio" ]]; then
echo "$(tput setaf 1)ERROR: Unknown ratio for density $DPI$(tput sgr0)"
exit
fi
SRC_DIR=`pwd`'/';
RES_DIR=$SRC_DIR'res/';
# copy to DPI
echo "$(tput setaf 4)Copying $DPI...$(tput sgr0)"
DEST_DIR=$RES_DIR'drawable-'$DPI'/';
mkdir -p $DEST_DIR;
for item in $( find . -type f -maxdepth 1 \( ! -iname ".png" \) | sed 's@./@@' ); do
echo Copying: $item
cp $SRC_DIR$item $DEST_DIR$item
done
SRC_DIR=$DEST_DIR
for density in ${(k)densities}; do
if [[ $density == $DPI ]]; then
echo "$(tput setaf 4)Not resizing $density as already was copied...$(tput sgr0)"
continue
fi
current_ratio=$densities[$density]
((percentage=current_ratio*100.0/ratio))
# resize density
echo "$(tput setaf 4)Start resizing $density...$(tput sgr0)"
DEST_DIR=$RES_DIR"drawable-$density/";
mkdir -p $DEST_DIR;
resize.sh $SRC_DIR $DEST_DIR $percentage'%'
done
echo "$(tput setaf 2)Done :)$(tput sgr0)"
#! /bin/bash
# This command can be used as an alias for adb and it will prompt for the
# device selection if needed
# alias adb=my-adb
set +x
set -e
if [ $# == 0 ]
then
# no arguments
exec adb
elif [ "$1" == 'devices' ]
then
# adb devices should not accept -s, -e or -d
exec adb devices
elif [ "$1" == 'kill-server' ]
then
# adb kill-server should not accept -s, -e or -d
exec adb kill-server
elif [ "$1" == 'connect' ]
then
exec adb "$@"
else
# because of the set -e, if selecting the device fails it exits
S=$(android-select-device "$@")
exec adb $S "$@"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment