feat(bash): pass n dots to .. function to cd n parents up

This commit is contained in:
Victor Westerlund 2025-12-05 13:23:42 +01:00
parent 2fa3e8475d
commit 4033dfaf80
Signed by: vlw
GPG key ID: D0AD730E1057DFC6

View file

@ -94,6 +94,20 @@ lll () {
} }
.. () { .. () {
# Count the number of dots in the first argument
local count=$(echo "$1" | grep -o "\." | wc -l)
# Check if count is greater than zero
if [ "$count" -gt 0 ]; then
# Construct the path to go up n directories
local path="$(printf '../%.0s' $(seq 1 $count))"
# Change the directory
cd $path || echo "Failed to change directory."
l
return
fi
cd .. && l cd .. && l
} }