Last active
May 8, 2023 10:22
-
-
Save legendmohe/d511e67e80ae0e3afdef0b1faea6d2da to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Set-Culture en-US | |
$env:LC_ALL='C.UTF-8' | |
$env:PYTHONIOENCODING='utf-8' | |
# load modules | |
Import-Module posh-git | |
Import-Module PSReadLine | |
Import-Module ZLocation | |
# Chocolatey profile | |
$ChocolateyProfile = "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1" | |
if (Test-Path($ChocolateyProfile)) { | |
Import-Module "$ChocolateyProfile" | |
} | |
# Git | |
function git_branch_fzf { | |
git branch -a | fzf | %{$_ -replace "^[ \*]+", ""} | |
} | |
function git_checkout_fzf { | |
gfb | %{git checkout $_} | |
} | |
function git_new_branch_fzf { | |
$selected_branch = gfb | |
if (!($NEW_BRANCH = Read-Host "default new branch name: [$selected_branch]")) { | |
$NEW_BRANCH = $selected_branch | |
} | |
$NEW_BRANCH = $NEW_BRANCH.replace("remotes/origin/", "") | |
if ($NEW_BRANCH) { | |
%{git checkout -b $NEW_BRANCH $selected_branch} | |
} | |
} | |
function git_branch_hash_fzf { | |
git log --pretty=format:"%C(yellow)%h%Creset %ad | %Cgreen%s%Creset %Cred%d%Creset %Cblue[%an]" --date=short | fzf | %{($_ -split " ")[0]} | |
} | |
Set-Alias gfb git_branch_fzf | |
Set-Alias gfc git_checkout_fzf | |
Set-Alias gfnb git_new_branch_fzf | |
Set-Alias gfbh git_branch_hash_fzf | |
# android | |
function adb_list_devices { | |
return adb devices -l | Select-String "(\w+)\s+device " | |
} | |
function adb_list_devices_hash { | |
return adb_list_devices | % {$_.matches.groups[1].value} | |
} | |
function adb_device_count { | |
return (adb_list_devices).count | |
} | |
function adb_select_device { | |
return adbld | fzf | Select-String "(\w+)\s+device " | % {$_.matches.groups[1].value} | |
} | |
function adb_pull($path) { | |
$device_count = adb_device_count | |
if ($device_count -eq 0) { | |
echo "no android devices" | |
return | |
} | |
if (-not $PSBoundParameters.ContainsKey('path')) { | |
echo "empty path param" | |
return | |
} | |
$target_device = "" | |
$target_device_prefix = "" | |
if ($device_count -gt 1) { | |
$target_device = adb_select_device | |
$target_device_prefix = "-s $target_device" | |
} | |
$target_file = Invoke-Expression("adb $target_device_prefix shell ls -la $path") | fzf | % { $_.split()[-1]} | |
if ($target_file) { | |
echo "pulling $target_file to $pwd" | |
Invoke-Expression "adb $target_device_prefix pull $path/$target_file" | |
} | |
} | |
function adb_shell($adbCmd) { | |
$device_count = adb_device_count | |
if ($device_count -eq 0) { | |
echo "no android devices" | |
return | |
} | |
$target_device = "" | |
$target_device_prefix = "" | |
if ($device_count -gt 1) { | |
$target_device = adb_select_device | |
$target_device_prefix = "-s $target_device" | |
} | |
Invoke-Expression("adb $target_device_prefix shell $adbCmd") | |
} | |
Set-Alias adbld adb_list_devices | |
Set-Alias adbp adb_pull | |
Set-Alias adbshell adb_shell | |
# Theme | |
# Set-Theme Avit | |
# others | |
Set-Alias gw ./gradlew | |
Set-PSReadLineKeyHandler -Key Tab -Function Complete | |
Set-PSReadLineKeyHandler -Key "Ctrl+d" -Function MenuComplete | |
# Set-PSReadLineKeyHandler -Key "Ctrl+z" -Function Undo | |
Set-PSReadLineOption -HistorySearchCursorMovesToEnd | |
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward | |
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment