Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Jumpei Matsuda jmatsu

🏠
Working from home
View GitHub Profile
@jmatsu
jmatsu / script-template.sh
Created Jun 29, 2021 — forked from m-radzikowski/script-template.sh
Minimal safe Bash script template - see the article with full description: https://betterdev.blog/minimal-safe-bash-script-template/
View script-template.sh
#!/usr/bin/env bash
set -Eeuo pipefail
trap cleanup SIGINT SIGTERM ERR EXIT
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P)
usage() {
cat <<EOF
Usage: $(basename "${BASH_SOURCE[0]}") [-h] [-v] [-f] -p param_value arg1 [arg2...]
View example.bash
# Register a filter command for Git commands
git config --system --add mine.filter fzf
# Show checked-out branches in reflog (distinct, and not sorted by the checked-out time)
git config --system --add alias.head-history "\!f() { git reflog HEAD | grep 'checkout:' | awk '\$0=\$NF' | sort | uniq; }; f"
# Select and switch HEAD to the branch
git config --system --add alias.switch-to "\!f() { local -r ref=\"\$(git head-history | \$(git config --get mine.filter))\"; [[ -n \"\$ref\" ]] && git switch \"\$ref\"; }; f"
View packaged
https://github.com/jmatsu/mc-migration
@jmatsu
jmatsu / get_default_branch_name.sh
Last active Aug 1, 2020
To avoid default branch name chaos
View get_default_branch_name.sh
# get the default branch of the current repository. NOTE that this will requires the network connection
git config --global alias.default-branch "\!f() { git ls-remote --symref \$(git remote get-url origin) HEAD | grep 'refs/heads' | awk '\$0=\$2' | sed 's/refs\/heads\///'; }; f"
# then run git default-branch
View old_install.sh
export ANDROID_HOME="$HOME/sdk"
curl -o sdk-tools.zip "https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip"
unzip "sdk-tools.zip" -d $ANDROID_HOME
$ANDROID_HOME/tools/bin/sdkmanager <package>...
View new_install.sh
# BAD
export ANDROID_HOME="$HOME/sdk"
curl -o sdk-tools.zip "https://dl.google.com/android/repository/commandlinetools-linux-6514223_latest.zip"
unzip "sdk-tools.zip" -d $ANDROID_HOME
$ANDROID_HOME/tools/bin/sdkmanager <package>...
# GOOD
export ANDROID_SDK_ROOT="$HOME/sdk"
mkdir -p $ANDROID_SDK_ROOT/cmdline-tools
curl -o sdk-tools.zip "https://dl.google.com/android/repository/commandlinetools-linux-6514223_latest.zip"
View install.bash
die() {
echo "$*" >&2
exit 1
}
warn() {
echo "$*" >&2
}
if [[ ! -d ".git/hooks" ]]; then
View gist:2efe9c0e33673dbfaffcfbcd76b42b69
#!/usr/bin/env bash
set -eux
mkdir -p tmp || :
cd tmp
: "${size:=240}"
: "${img_size:=$size}"
@jmatsu
jmatsu / build.gradle
Last active Dec 11, 2018
bintray's maven repositories under Google, Android and Firebase
View build.gradle
maven { url "https://android.bintray.com/android-tools/" }
maven { url "https://android.bintray.com/android-utils/" }
maven { url "https://android.bintray.com/android-support/" }
maven { url "https://android.bintray.com/android-jack/" }
maven { url "https://firebase.bintray.com/gradle/" }
maven { url "https://firebase.bintray.com/geofire/" }
maven { url "https://firebase.bintray.com/firebase-jobdispatcher/" }
maven { url "https://firebase.bintray.com/digits-migration-helper-android/" }
maven { url "https://firebase.bintray.com/maven/" }
maven { url "https://google.bintray.com/interactivemedia/" }
View git-file-pick
#!/usr/bin/env bash
set -eu
set -o pipefail
filter_files() {
local -r ref_name="$1"
# select files by TAB
git --no-pager diff --diff-filter=ACMU --name-only "$ref_name" | fzf -m
}