mirror of
https://github.com/lloeki/dotfiles.git
synced 2025-12-06 07:24:39 +01:00
Add capturable output to kd
This commit is contained in:
parent
2cd00b16f2
commit
00d9c4051d
1 changed files with 23 additions and 9 deletions
32
shell/kd
32
shell/kd
|
|
@ -1,13 +1,22 @@
|
|||
# vim: ft=sh
|
||||
# shellcheck shell=bash
|
||||
|
||||
# worKDir
|
||||
function kd() {
|
||||
local conf="$HOME/.kdrc"
|
||||
if [[ $# -eq 0 ]]; then
|
||||
local candidate="$PWD"
|
||||
while [[ -n "$candidate" ]]; do
|
||||
for file in Gemfile Procfile; do
|
||||
if [[ -f "$candidate/$file" ]]; then
|
||||
cd "$candidate"
|
||||
return $?
|
||||
for file in Gemfile Procfile .git; do
|
||||
if [[ -e "$candidate/$file" ]]; then
|
||||
if [[ -t 1 ]]; then
|
||||
cd "$candidate" || return 1
|
||||
return
|
||||
else
|
||||
[[ -d "$target" ]] || return 1
|
||||
echo "$candidate"
|
||||
return
|
||||
fi
|
||||
fi
|
||||
done
|
||||
candidate="${candidate%/*}"
|
||||
|
|
@ -18,16 +27,23 @@ function kd() {
|
|||
local target
|
||||
target="$(grep -e "^$1" "$conf" | awk '{ print $2 }' | tail -1)"
|
||||
if [[ -n "$target" ]]; then
|
||||
cd "$target"
|
||||
return $?
|
||||
if [[ -t 1 ]]; then
|
||||
cd "$target" || return 1
|
||||
return
|
||||
else
|
||||
[[ -d "$target" ]] || return 1
|
||||
echo "$target"
|
||||
return
|
||||
fi
|
||||
fi
|
||||
return 1
|
||||
fi
|
||||
if [[ $# -eq 2 ]]; then
|
||||
local target
|
||||
local name
|
||||
name="$1"
|
||||
if [[ -d "$2" ]]; then
|
||||
target=$(cd "$2"; pwd)
|
||||
target=$(cd "$2" && pwd)
|
||||
if [[ -n "$target" ]]; then
|
||||
sed -i -e "/^$name/d" "$conf"
|
||||
echo "$name" "$target" >> "$conf"
|
||||
|
|
@ -36,5 +52,3 @@ function kd() {
|
|||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# vim: ft=sh
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue