Skip to content

Commit 7a2c0ad

Browse files
committedMar 15, 2025
.
1 parent dc3e40e commit 7a2c0ad

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed
 

‎fish/alias-and-functions.fish

+22-8
Original file line numberDiff line numberDiff line change
@@ -1109,29 +1109,43 @@ function b
11091109
end
11101110

11111111
function mc --description "go build and install a binary"
1112-
if test (count $argv) -lt 1
1113-
echo "Usage: mc <binary-name>"
1114-
return 1
1112+
set -l binary_name
1113+
1114+
# Check if an argument is provided
1115+
if test (count $argv) -eq 0
1116+
# No argument provided, check for directories in cmd/
1117+
set -l cmd_dirs (path filter -d cmd/*)
1118+
set -l num_dirs (count $cmd_dirs)
1119+
1120+
if test $num_dirs -eq 1
1121+
# Exactly one directory found, use it as the binary name
1122+
set binary_name (basename $cmd_dirs[1])
1123+
else
1124+
# Zero or multiple directories found, prompt for binary name
1125+
echo "Error: Please specify the binary name. Found $num_dirs directories in cmd/."
1126+
return 1
1127+
end
1128+
else
1129+
# Use the provided argument as the binary name
1130+
set binary_name $argv[1]
11151131
end
11161132

1117-
set -l binary_name $argv[1]
11181133
set -l gopath (go env GOPATH)
11191134

11201135
# Build the binary locally
1121-
echo "Building $binary_name locally..."
1136+
# echo "Building $binary_name locally..."
11221137
go build -o $binary_name ./cmd/$binary_name
11231138
if test $status -ne 0
11241139
echo "Build failed"
11251140
return 1
11261141
end
11271142

11281143
# Install the binary to $GOPATH/bin
1129-
echo "Installing $binary_name..."
1144+
# echo "Installing $binary_name..."
11301145
go install ./cmd/$binary_name
11311146
if test $status -ne 0
11321147
echo "Failed to install $binary_name"
11331148
return 1
11341149
end
1135-
1136-
echo "$binary_name installed successfully to $gopath/bin"
1150+
echo "$binary_name installed"
11371151
end

0 commit comments

Comments
 (0)
Failed to load comments.