Last active
May 9, 2025 13:06
-
-
Save meodai/0f34b4c084dc30687b6038255811c5af to your computer and use it in GitHub Desktop.
Fish shell function that runs a local server on a given direcotry
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Usage: apatschi [directory] | |
# Description: Starts a local server with BrowserSync for the specified directory. | |
function apatschi | |
set dir "." | |
if test (count $argv) -gt 0 | |
set dir $argv[1] | |
end | |
if not test -d $dir | |
echo "❌ Directory '$dir' does not exist." | |
return 1 | |
end | |
set index_param "" | |
if not test -f "$dir/index.html" | |
set html_files (glob "$dir"/*.htm "$dir"/*.html) | |
if test (count $html_files) -gt 0 | |
set index_param "--index $html_files[1]" | |
else | |
echo "⚠️ No HTML file found in '$dir'." | |
return 1 | |
end | |
end | |
npx browser-sync start \ | |
--server "$dir" \ | |
--files "$dir/**/*.css,$dir/**/*.html,$dir/**/*.js" \ | |
$index_param | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apatschi() { | |
dir="." | |
if [ $# -gt 0 ]; then | |
dir="$1" | |
fi | |
if [ ! -d "$dir" ]; then | |
echo "❌ Directory '$dir' does not exist." | |
return 1 | |
fi | |
index_param="" | |
if [ ! -f "$dir/index.html" ]; then | |
html_files=("$dir"/*.htm "$dir"/*.html) | |
if [ -f "${html_files[0]}" ]; then | |
index_param="--index ${html_files[0]}" | |
else | |
echo "⚠️ No HTML file found in '$dir'." | |
return 1 | |
fi | |
fi | |
npx browser-sync start \ | |
--server "$dir" \ | |
--files "$dir/**/*.css,$dir/**/*.html,$dir/**/*.js" \ | |
$index_param | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment