Skip to content

Commit cd5e2c0

Browse files
committed
interactive: support view and custom filename
1 parent f0674a8 commit cd5e2c0

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

git-recover

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,15 @@ function print_recoverable {
175175
done
176176
}
177177

178+
function prompt_for_filename {
179+
echo -n "Filename (return to skip): "
180+
read -r FILENAME
181+
}
182+
183+
function view_file {
184+
read_one_file "${BLOB}" | ${PAGER:-less}
185+
}
186+
178187
function show_summary {
179188
FILETYPE=$(read_one_file "${BLOB}" | file -b -)
180189
IS_TEXT=$(echo "${FILETYPE}" | grep -c ' text$' 2>/dev/null || true)
@@ -203,7 +212,7 @@ function interactive {
203212

204213
while true
205214
do
206-
echo -n "Recover this file? [y,n,q]: "
215+
echo -n "Recover this file? [y,n,v,f,q,?]: "
207216
read -r ans || return 1
208217

209218
case "$ans" in
@@ -214,7 +223,31 @@ function interactive {
214223
[nN]*)
215224
break
216225
;;
217-
[qQ]*)
226+
[vV]*)
227+
view_file "${BLOB}"
228+
echo
229+
;;
230+
[fF]*)
231+
prompt_for_filename
232+
233+
if [ "$FILENAME" == "" ]; then
234+
break
235+
fi
236+
237+
write_one_file "${BLOB}" "${FILENAME}" "${FILENAME}"
238+
break
239+
;;
240+
\?*)
241+
echo
242+
echo "Do you want to recover this file?"
243+
echo " y: yes, write the file to ${BLOB}"
244+
echo " n: no, skip this file and see the next orphaned file"
245+
echo " v: view the file"
246+
echo " f: prompt for a filename to use for recovery"
247+
echo " q: quit"
248+
echo
249+
;;
250+
[qQ]*)
218251
return 0
219252
;;
220253
esac

0 commit comments

Comments
 (0)