11#! /usr/bin/env bash
22
33fuzzycd_run () {
4- local version=" 0.2.4 "
4+ local version=" 0.2.5 "
55 local histfile=${FUZZYCD_HISTORY_FILE:- " $HOME /.fuzzycd-history" }
66
77 _fzcd_is_dirname () {
@@ -89,6 +89,24 @@ fuzzycd_run() {
8989 echo " fuzzycd $version "
9090 }
9191
92+ _fzcd_prune_history () {
93+ local dir tmpfile removed
94+ tmpfile=$( mktemp " ${histfile} .XXXXXX" ) || return 1
95+ removed=0
96+
97+ while IFS= read -r dir; do
98+ if [[ -d " $dir " ]]; then
99+ echo " $dir " >> " $tmpfile "
100+ else
101+ echo " pruned $dir "
102+ removed=1
103+ fi
104+ done < " $histfile "
105+
106+ mv " $tmpfile " " $histfile "
107+ [[ $removed -eq 0 ]] && echo " nothing to prune"
108+ }
109+
92110 _fzcd_delete_dir () {
93111 dir=" ${1:- $PWD } "
94112 grep -Fxv " $dir " " $histfile " > " $HOME /.fuzzycd-history.tmp"
@@ -106,6 +124,7 @@ fuzzycd_run() {
106124 echo " cd -l list history with fzf"
107125 echo " cd -e edit history file"
108126 echo " cd -s show history file"
127+ echo " cd -p prune non-existent directories from history"
109128 echo " cd -d [DIR] delete current or specified directory from history"
110129 echo " cd -c show completions function [usage: eval \"\$ (cd -c)\" ]"
111130 echo " cd -v show version"
@@ -161,6 +180,7 @@ fuzzycd_run() {
161180 " -v" ) _fzcd_show_version ;;
162181 " -e" ) _fzcd_edit_histfile ;;
163182 " -s" ) _fzcd_show_histfile ;;
183+ " -p" ) _fzcd_prune_history ;;
164184 " -c" ) _fzcd_show_completions ;;
165185 " -d" )
166186 shift
0 commit comments