diff --git a/fishyindex b/fishyindex new file mode 100755 index 0000000..10a7377 --- /dev/null +++ b/fishyindex @@ -0,0 +1,33 @@ +#!/usr/bin/fish + +function mkindex + set DIR $argv[1] + set FILE $DIR/index.html + echo "Index of $DIR" > $FILE + echo "

Index of $DIR


" >> $FILE + printf '

Generated on %s\n

' (date) >> $FILE + echo "" >> $FILE + echo "" >> $FILE + for f in $DIR/* + set FILENAME (basename $f) + if test -d $f + set FILENAME "$FILENAME/" + end + set TIMESTAMP (date -r $f) + echo "" >> $FILE + end + echo "
NameLast Modified
$FILENAME$TIMESTAMP
" >> $FILE +end + +function index-for-all + set DIR $argv[1] + mkindex $DIR + + for d in $DIR/* + if test -d $d + index-for-all $d + end + end +end + +index-for-all (pwd) diff --git a/transcript.txt b/transcript.txt new file mode 100644 index 0000000..b3db609 --- /dev/null +++ b/transcript.txt @@ -0,0 +1,101 @@ +Note: final tweaked code at: https://git.tilde.town/kindrobot/fishyindex + +> Write a fish function that writes an index.html file for directory passed to it. + +As an AI language model, I don't have the ability to write code files directly. However, I can provide you with an example of a fish function that generates an index.html file for a given directory: + + function mkindex + set DIR $argv[1] + set FILE $DIR/index.html + echo "Index of $DIR" > $FILE + echo "

Index of $DIR


" >> $FILE + echo "" >> $FILE + end + +To use this function, you can save it in your fish configuration file (usually ~/.config/fish/config.fish) and then run it with the name of the directory you want to generate an index.html file for: + + mkindex /path/to/directory + +This will create an index.html file in the specified directory that contains a list of all the files in the directory as hyperlinks. You can then view this file in a web browser to navigate the directory contents. + +> Write a fish function that takes a directory and +> 1. calls mkindex for that directory +> 2. calls mkindex for each sub-directory recursively + +Sure, here's an example fish function that calls mkindex for a given directory and recursively for each subdirectory: + + function mkindex-recursive + set DIR $argv[1] + mkindex $DIR + + for d in $DIR/* + if test -d $d + mkindex-recursive $d + end + end + end + +To use this function, save it in your fish configuration file (usually ~/.config/fish/config.fish) and then run it with the name of the top-level directory you want to generate index.html files for: + + mkindex-recursive /path/to/top-level-directory + +This will call mkindex for the top-level directory and then recursively for each subdirectory in the directory tree. The result will be an index.html file in each directory that contains a list of all the files in that directory as hyperlinks, as well as links to the index.html files in any subdirectories. + +> Modify mkindex so that the generated index is a monospace font and includes a timestamp of when the file was last modified. + +Certainly, here's an updated version of the mkindex function that generates an index with a monospace font and includes a timestamp of when the file was last modified: + + function mkindex + set DIR $argv[1] + set FILE $DIR/index.html + echo "Index of $DIR" > $FILE + echo "

Index of $DIR


" >> $FILE + echo "

Generated on $(date)

" >> $FILE + echo "" >> $FILE + end + +The changes include: + +Adding the style="font-family: monospace;" attribute to the body tag to set the font to monospace. +Adding a timestamp to the index using the date command with the -r option to get the last modified time of each file. This timestamp is included in each file's list item with a gray color. +You can use this updated mkindex function in the mkindex-recursive function from my previous answer to generate monospace indexes with timestamps for directories and subdirectories recursively. + +> Modify mkindex so that it each entry also includes the filename + +Sure, here's an updated version of the mkindex function that generates an index with a monospace font, includes a timestamp of when the file was last modified, and also displays the filename for each entry: + + function mkindex + set DIR $argv[1] + set FILE $DIR/index.html + echo "Index of $DIR" > $FILE + echo "

Index of $DIR


" >> $FILE + echo "

Generated on $(date)

" >> $FILE + echo "" >> $FILE + echo "" >> $FILE + for f in $DIR/* + set FILENAME (basename $f) + set TIMESTAMP (date -r $f) + echo "" >> $FILE + end + echo "
NameLast Modified
$FILENAME$TIMESTAMP
" >> $FILE + end + +The changes include: + +Wrapping the index entries in a table element to display them in a tabular format. +Adding a thead element to contain the table headers. +Adding a tbody element to contain the table rows. +Adding a Name header to the table. +Adding a new basename command to extract the filename from the full file path. +Adding a Name column to each table row that displays the filename. +Modifying the Last Modified column to display the timestamp without the gray color. +You can use this updated mkindex function in the mkindex-recursive function from my previous answer to generate indexes that display both the filename and timestamp for directories and subdirectories recursively.