mirror of
https://github.com/Ahwxorg/nixos-config.git
synced 2026-03-19 15:50:30 +01: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}"
|
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 () {
|
function nixcd () {
|
||||||
PACKAGE_NAME="$1"
|
PACKAGE_NAME="$1"
|
||||||
if [[ "$PACKAGE_NAME" = "" ]]; then
|
if [[ "$PACKAGE_NAME" = "" ]]; then
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue