mirror of
https://github.com/Ahwxorg/nixos-config.git
synced 2026-02-22 21:05:14 +08:00
feat: adds more zsh functions (cdfile/get-git-root/cd-git-root/pushd-git-root-widget)
This commit is contained in:
parent
b536f9d776
commit
7dec0745a6
1 changed files with 32 additions and 0 deletions
|
|
@ -128,6 +128,38 @@
|
|||
printf "%s\n" "''${url}"
|
||||
}
|
||||
|
||||
function cd() {
|
||||
if [ -f "$1" ]; then
|
||||
${pkgs.zoxide}/bin/zoxide "$(dirname "$1")"
|
||||
return
|
||||
fi
|
||||
|
||||
${pkgs.zoxide}/bin/zoxide $@
|
||||
}
|
||||
|
||||
get-git-root() {
|
||||
echo "$(${pkgs.git}/bin/git rev-parse --show-toplevel 2>/dev/null)"
|
||||
}
|
||||
|
||||
cd-git-root() {
|
||||
pushd "$(get-git-root)"
|
||||
}
|
||||
|
||||
pushd-git-root-widget() {
|
||||
setopt localoptions pipefail no_aliases 2> /dev/null
|
||||
local dir="$(eval "get-git-root")"
|
||||
if [[ -z "$dir" ]]; then
|
||||
zle redisplay
|
||||
return 0
|
||||
fi
|
||||
zle push-line
|
||||
BUFFER="builtin pushd -- ''${(q)dir}"
|
||||
zle accept-line
|
||||
local ret=$?
|
||||
zle reset-prompt
|
||||
return $ret
|
||||
}
|
||||
|
||||
function nixcd () {
|
||||
PACKAGE_NAME="$1"
|
||||
if [[ "$PACKAGE_NAME" = "" ]]; then
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue