Skip to content

Instantly share code, notes, and snippets.

@YuanLiou
Last active September 23, 2024 09:49
Show Gist options
  • Save YuanLiou/54074ab186e700c3682d50ff5c57f8a5 to your computer and use it in GitHub Desktop.
Save YuanLiou/54074ab186e700c3682d50ff5c57f8a5 to your computer and use it in GitHub Desktop.
Ray's zsh config 1.0.2
# Function
function showLogs {
git log --pretty=format:'- %s' --since="$1" --author="$2"
}
# Convert video to gif file.
# Usage: video2gif video_file (scale) (fps)
video2gif() {
ffmpeg -y -i "${1}" -vf fps=${3:-10},scale=${2:-320}:-1:flags=lanczos,palettegen "${1}.png"
ffmpeg -i "${1}" -i "${1}.png" -filter_complex "fps=${3:-10},scale=${2:-320}:-1:flags=lanczos[x];[x][1:v]paletteuse" "${1}".gif
rm "${1}.png"
}
# Optimize mp4
# Usage: optimizeVideo video_file (scale) (fps)
optimizeVideo() {
ffmpeg -i "${1}" -vcodec h264 -acodec mp2 "${1}".mp4
}
# Adb device chooser, install fzf first
function adb() {
# Execute the actual command
local totalLines=$(command adb devices | wc -l | xargs)
local totalDeviceConnected=$(expr $totalLines - 2)
if [[ "$@" != *"-s "* && $totalDeviceConnected -gt 1 ]]; then
# Get the list of connected devices
devices=(`command adb devices | awk '$2 == "device" {print $1}' | grep -v '^$'`)
devicesText=""
# Loop through each device
for device in $devices; do
# Get the market name property
market_name=$(adb -s "$device" shell getprop ro.product.vendor.marketname)
# Check if market name is empty
if [ -z "$market_name" ]; then
# Get the model property if market name is empty
market_name=$(adb -s "$device" shell getprop ro.product.model)
fi
devicesText+="$device - $market_name\n"
done
# Prompt user to select a device
local selection=$(echo -e $devicesText | grep -v '^$' | fzf)
local deviceId=$(echo $selection | awk '{print $1}')
GREEN='\033[0;32m'
NC='\033[0m' # No Color
echo -e "📱 Device Selected: ${GREEN}$selection${NC}"
# Execute adb command on the selected device
command adb -s $deviceId "$@"
else
# Execute the command without device selection
command adb "$@"
fi
return
}
# endregion Function
# Alias
alias cla='colorls -lA --sd'
alias cls='colorls'
alias cb='swagit'
## Navigation
alias ..='cd ..'
alias ...='cd ../..'
alias .3='cd ../../..'
alias .4='cd ../../../..'
alias .5='cd ../../../../..'
alias ruo='git fetch upstream && git checkout develop && git merge --ff-only upstream/develop && git push origin develop'
alias ruom='git fetch upstream && git checkout master && git merge --ff-only upstream/master && git push origin master'
alias ruomain='git fetch upstream && git checkout main && git merge --ff-only upstream/main && git push origin main'
alias update_master='git fetch upstream && git checkout shp_master && git merge --ff-only upstream/shp_master && git push origin shp_master'
alias reload='exec $SHELL -l'
alias standup="git log --since '1 day ago' --oneline --pretty=format':%C(yellow)%h %aN%n %B%n' --author Ray"
alias RUO='git fetch upstream && git checkout develop && git merge --ff-only upstream/develop && git push origin develop --no-verify'
# use Tmux only if current term program is Apple Terminal
source "$HOME/apple_term_tmux.sh"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment