mirror of
https://github.com/mqttr/dotfiles.git
synced 2025-12-15 04:25:50 -06:00
feat(zsh): update forget and forgetall
This commit is contained in:
58
zsh/.zshrc
58
zsh/.zshrc
@@ -198,32 +198,46 @@ function extract()
|
|||||||
}
|
}
|
||||||
|
|
||||||
forget () {
|
forget () {
|
||||||
print "Forgetting last line with '$@'. Please reload shell after completion."
|
if [ -z "$@" ]; then
|
||||||
|
echo "ERROR: No keyword given"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
temp=$(mktemp)
|
echo "Forgetting last command with '$@'."
|
||||||
|
|
||||||
sed -e '$ d' ~/.zsh_history | tac | awk "!/$@/ || f++" | tac > $temp
|
new_zsh_history=$(tac ~/.zsh_history | awk "/$@/ && p<2 {p++; next}1" | tac)
|
||||||
print "Difference between .zsh_history and new .zsh_history"
|
print "Difference between .zsh_history and new .zsh_history"
|
||||||
diff ~/.zsh_history $temp
|
echo $new_zsh_history | diff ~/.zsh_history -
|
||||||
|
|
||||||
mv $temp ~/.zsh_history
|
read answer
|
||||||
|
if [ "$answer" = "y" ]; then
|
||||||
if [ -f $temp ]; then
|
echo $new_zsh_history > ~/.zsh_history
|
||||||
rm -f $temp
|
echo "Last line with '$@' forgotten"
|
||||||
|
echo "You will need to reload your shell for the changes to take effect."
|
||||||
|
else
|
||||||
|
echo "Changes not applied."
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
forgetall () {
|
forgetall () {
|
||||||
print "Forgetting all lines with '$@'. Please reload shell after completion."
|
if [ -z "$@" ]; then
|
||||||
|
echo "ERROR: No keyword given"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
temp=$(mktemp)
|
echo "Forgetting all command with '$@'."
|
||||||
sed "/$@/d" ~/.zsh_history > $temp
|
|
||||||
|
new_zsh_history=$(grep --inverse-match "$@" ~/.zsh_history)
|
||||||
print "Difference between .zsh_history and new .zsh_history"
|
print "Difference between .zsh_history and new .zsh_history"
|
||||||
diff ~/.zsh_history $temp
|
echo $new_zsh_history | diff ~/.zsh_history -
|
||||||
mv $temp ~/.zsh_history
|
|
||||||
|
|
||||||
if [ -f $temp ]; then
|
read -p 'Apply changes? (y/n): ' answer
|
||||||
rm -f $temp
|
if [ "$answer" = "y" ]; then
|
||||||
|
echo $new_zsh_history > ~/.zsh_history
|
||||||
|
echo "Last line with '$@' forgotten"
|
||||||
|
echo "You will need to reload your shell for the changes to take effect."
|
||||||
|
else
|
||||||
|
echo "Changes not applied."
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -237,17 +251,3 @@ fcd() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
tcd() {
|
|
||||||
DIR=$(mktemp -d 2>/dev/null)
|
|
||||||
if [[ -e "$DIR" ]]; then
|
|
||||||
cd $DIR
|
|
||||||
print "Moved to \"$DIR\""
|
|
||||||
else
|
|
||||||
print "\"$DIR\" failed to be created"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
ttcd() {
|
|
||||||
cd /tmp
|
|
||||||
tcd
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user