Skip to content

Instantly share code, notes, and snippets.

@igor-makarov
Last active January 28, 2022 12:14
Show Gist options
  • Save igor-makarov/9722ca35e703f0024a4842244d258ffa to your computer and use it in GitHub Desktop.
Save igor-makarov/9722ca35e703f0024a4842244d258ffa to your computer and use it in GitHub Desktop.
Bash scripts

My bash scripts

Usage

Add the following line to to .bashrc or .bash_profile:

if ! [ -d ~/.bash_scripts ]; then
    git clone https://gist.github.com/9722ca35e703f0024a4842244d258ffa.git .bash_scripts
    git -C ~/.bash_scripts branch -u origin/master
fi
source ~/.bash_scripts/bash-scripts.sh
#!/bin/bash -l
# usage: add the following lines to .bashrc or .bash_profile:
# if ! [ -d ~/.bash_scripts ]; then
# git clone https://gist.github.com/9722ca35e703f0024a4842244d258ffa.git .bash_scripts
# git -C ~/.bash_scripts branch -u origin/master
# fi
# source ~/.bash_scripts/bash-scripts.sh
pull-bash-scripts () {
git -C ~/.bash_scripts pull
}
# delete remote branch
git-rm-remote () {
git push origin :$1
}
# rename remote branch
git-mv-remote () {
mv .git/hooks/post-checkout .git/hooks/post-checkout.tmp || true
(
set -x -e
prev_branch=$(git rev-parse --abbrev-ref HEAD)
git checkout -b temp origin/$1
git push origin temp:$2
git push origin :$1
git checkout $prev_branch
git branch -D temp
)
mv .git/hooks/post-checkout.tmp .git/hooks/post-checkout || true
}
# is $1 upstream from $2?
git-is-downstream () {
(
git merge-base --is-ancestor $1 $2
retval=$?
if [[ $retval -eq 0 ]]; then
>&2 echo "true"
else
>&2 echo "false"
fi
exit $retval
)
}
without-hooks () {
(
git config core.hooksPath "/"
"$@"
retval=$?
git config --unset core.hooksPath
exit $retval
)
}
# pull all other branches
ppp () {
branches=`git branch | grep -v '*'`
for branch in $branches; do
echo "$branch"
git fetch origin $branch:$branch
done
}
# hard discard
git-discard-hard () {
git checkout .
git clean -f -d
}
# open xcode on workspace or project in current dir
xc () {
( open -a $(xcode-select -print-path)/../.. ./ ) > /dev/null 2>&1
}
# run xunique on project
xu () {
if [[ "$1" == "" ]]; then
xunique *.xcodeproj
else
xunique $1
fi
}
# quit Xcode gracefully, kill it if it is not being graceful
xcq () {
( osascript -e 'tell app "Xcode" to quit' & ) 2>/dev/null
( (
sleep 2
kill $(ps aux | grep -e 'app/Contents/MacOS/Xcode' | grep -v grep | awk '{print $2}')
) > /dev/null 2>&1 & ) 2>/dev/null
}
has-bitcode () {
otool -arch all -l "$1" | grep __bitcode &> /dev/null
has=$?
[[ $has -eq 0 ]] && echo "has" || echo "not"
return $has
}
lipo-thin () {
bn="$(basename $1)"
ext="${bn##*.}"
if [ "$ext" == "$bn" ]; then
ext=""
fi
fn="${bn%.*}"
outfile="$(dirname $1)/$fn-$2$ext"
lipo "$1" -thin "$2" -output "$outfile"
}
strip-bitcode () {
xcrun bitcode_strip -r "$1" -o "$1-no-bc"
}
# open current dir as SourceTree repo
alias st='open -a SourceTree ./'
vc () {
[[ "" == "$1" ]] && code -n . || code -n "$@"
}
### test
@benjamingr
Copy link

Thanks! These were useful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment