Skip to content

Commit

Permalink
add makerun, and detect node package manager function
Browse files Browse the repository at this point in the history
  • Loading branch information
victory-sokolov committed Dec 30, 2023
1 parent 6757240 commit 042fcf6
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions zsh/.functions
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,40 @@ function bash-file() # Create new shell file
chmod +x "$FILE_PATH"
}

function makerun() # Run makefile command
{
local makefile_commands
makefile_commands=$(grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' Makefile | awk 'BEGIN {FS = ":.*?## "}{printf "%-30s %s\n", $1, $2}' | fzf --height 50% --ansi)

if [[ -n "$makefile_commands" ]]; then
local selected_command
selected_command=$(echo "$makefile_commands" | awk '{print $1}')
echo "Running 'make $selected_command'"
make "$selected_command"
else
echo "Exit: No command selected."
fi
}

function fnpm() # Run npm scripts interactively
{
package_manager=$(_get_node_package_manager)

if [ -f "package.json" ]; then
scripts=$(jq -r '.scripts | keys | .[]' package.json | fzf --height 50%)

if [[ -n "$scripts" ]]; then
script_name=$(echo "$scripts" | awk '{gsub(/"/, ""); print}')
echo "Running $package_manager run $script_name"
"$package_manager" run "$script_name"
else
echo "Exit: You haven't selected any script"
fi
else
echo "Exit: package.json not found"
fi
}

function repl() # Launch Repl for specified language
{
lang=$1
Expand Down Expand Up @@ -677,6 +711,21 @@ function node-flush() # Reinstall node deps
fi
}

# Get Node package manager
function _get_node_package_manager() {
if [[ -f bun.lockb ]]; then
echo "bun"
elif [[ -f pnpm-lock.yaml ]]; then
echo "pnpm"
elif [[ -f yarn.lock ]]; then
echo "yarn"
elif [[ -f package-lock.json ]]; then
echo "npm"
else
echo "pnpm"
fi
}

function p() # Determine package manager and run command with it
{
if [[ -f bun.lockb ]]; then
Expand Down

0 comments on commit 042fcf6

Please sign in to comment.