(bash) adding argument to fuzzy functions
This commit is contained in:
parent
89a65c525b
commit
886d4b02c8
1 changed files with 37 additions and 10 deletions
|
|
@ -117,7 +117,20 @@ sf() {
|
||||||
|
|
||||||
# fuzzy cd into specific folders
|
# fuzzy cd into specific folders
|
||||||
fcd() {
|
fcd() {
|
||||||
local selected_dir=$({
|
local selected_dir=""
|
||||||
|
|
||||||
|
if [ $# -eq 1 ]; then
|
||||||
|
selected_dir=$({
|
||||||
|
find "$HOME/.config" -maxdepth 1 -type d
|
||||||
|
find "$HOME/.config" -maxdepth 1 -type l
|
||||||
|
find "$HOME/.cache" -maxdepth 1 -type d
|
||||||
|
find "/mnt/smb" -maxdepth 1 -type d
|
||||||
|
echo "$HOME/Documents/Obsidian Vault"
|
||||||
|
find "$HOME/ghq" -mindepth 2 -maxdepth 2 -type d
|
||||||
|
ls -d -1 "$HOME/"/*/ | grep -v \.git
|
||||||
|
} | fzf --filter="$1" --select-1 --exit-0 | head -1)
|
||||||
|
else
|
||||||
|
selected_dir=$({
|
||||||
find "$HOME/.config" -maxdepth 1 -type d
|
find "$HOME/.config" -maxdepth 1 -type d
|
||||||
find "$HOME/.config" -maxdepth 1 -type l
|
find "$HOME/.config" -maxdepth 1 -type l
|
||||||
find "$HOME/.cache" -maxdepth 1 -type d
|
find "$HOME/.cache" -maxdepth 1 -type d
|
||||||
|
|
@ -126,6 +139,7 @@ fcd() {
|
||||||
find "$HOME/ghq" -mindepth 2 -maxdepth 2 -type d
|
find "$HOME/ghq" -mindepth 2 -maxdepth 2 -type d
|
||||||
ls -d -1 "$HOME/"/*/ | grep -v \.git
|
ls -d -1 "$HOME/"/*/ | grep -v \.git
|
||||||
} | fzf)
|
} | fzf)
|
||||||
|
fi
|
||||||
|
|
||||||
if [ -n "$selected_dir" ]; then
|
if [ -n "$selected_dir" ]; then
|
||||||
cd "$selected_dir"
|
cd "$selected_dir"
|
||||||
|
|
@ -199,6 +213,12 @@ git-prune() {
|
||||||
|
|
||||||
# fuzzy find branches and switch to selected branch
|
# fuzzy find branches and switch to selected branch
|
||||||
gc() {
|
gc() {
|
||||||
|
if [ $# -eq 1 ]; then
|
||||||
|
local selected_branch=$(git branch | grep "$1" | sed 's/^[ \*]*//')
|
||||||
|
git checkout "$selected_branch"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
local selected_branch=$(git branch | fzf | sed 's/^[ \*]*//')
|
local selected_branch=$(git branch | fzf | sed 's/^[ \*]*//')
|
||||||
|
|
||||||
if [ -n "$selected_branch" ]; then
|
if [ -n "$selected_branch" ]; then
|
||||||
|
|
@ -211,10 +231,17 @@ gc() {
|
||||||
# fuzzy find remote branches and switch to selected branch
|
# fuzzy find remote branches and switch to selected branch
|
||||||
gcr() {
|
gcr() {
|
||||||
git fetch
|
git fetch
|
||||||
|
|
||||||
|
if [ $# -eq 1 ]; then
|
||||||
|
local selected_branch=$(git branch | grep "$1" | sed 's/^([ \*]*origin\/[\ *]*)*//')
|
||||||
|
git switch "$selected_branch"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
local selected_branch=$(git branch -r | fzf | sed -E 's/^([ \*]*origin\/[\ *]*)*//')
|
local selected_branch=$(git branch -r | fzf | sed -E 's/^([ \*]*origin\/[\ *]*)*//')
|
||||||
|
|
||||||
if [ -n "$selected_branch" ]; then
|
if [ -n "$selected_branch" ]; then
|
||||||
git checkout "$selected_branch"
|
git switch "$selected_branch"
|
||||||
else
|
else
|
||||||
echo "No branch selected"
|
echo "No branch selected"
|
||||||
fi
|
fi
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue