Skip to content

Instantly share code, notes, and snippets.

@Alligator
Last active July 27, 2020 22:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Alligator/11e5bb01c12c8ac8b74824d54d1ee560 to your computer and use it in GitHub Desktop.
Save Alligator/11e5bb01c12c8ac8b74824d54d1ee560 to your computer and use it in GitHub Desktop.
@echo off
IF "%1" == "" (
echo %cd% >> %userprofile%\_k
) ELSE (
IF "%1" == "ls" (
type %userprofile%\_k
exit /B
)
FOR /F "tokens=* USEBACKQ" %%F IN (`findstr "%1" "%userprofile%\_k"`) DO (
cd %%F
exit /B
)
)
function k -a "path"
set k_file ~/.k
if test -z "$path"
echo (pwd) >> "$k_file"
else
switch "$path"
case "clean"
sort "$k_file" | uniq > "$k_file.tmp" && mv "$k_file.tmp" "$k_file"
case "rm"
sed -i -E "\#^"(pwd)"\$#d" "$k_file"
case "ls"
cat "$k_file"
case "*"
cd (grep -e "$path" "$k_file" | head -n 1)
end
end
end
k() {
if [ -z $1 ]; then
echo $PWD >> ~/.k
else
K=~/.k
case $1 in
clean) sort $K | uniq > ${K}.tmp && mv ${K}.tmp ${K};;
rm) sed -i -E "\#^${PWD}\$#d" ${K};;
ls) cat ${K};;
*) cd "$(grep -e "$1" ${K} | head -n 1)";;
esac
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment