-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathhelper.sh
More file actions
executable file
·48 lines (41 loc) · 1.17 KB
/
helper.sh
File metadata and controls
executable file
·48 lines (41 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env bash
# Check if the directory is provided as an argument
if [ $# -lt 1 ] || [ $# -gt 2 ]; then
echo "Usage: $0 <directory> [option]"
echo "Options:"
echo " -v | --version Print just the version number"
echo " -p | --path-version Print the concatenation of the path and the version"
exit 1
fi
# Check if the directory exists
if [ ! -d "$1" ]; then
echo "Directory '$1' does not exist"
exit 1
fi
# Append a trailing slash to the path if it's not already present
if [ "${1: -1}" != "/" ]; then
path="$1/"
else
path="$1"
fi
# Change into the directory and run the command
cd "$path" || exit 1
version=$(uv version)
# Get the version number
version_number="v${version##* }"
# Get the path and version string
path_version="$path$version_number"
# Handle options
if [ $# -eq 1 ]; then
# Default behavior: print just the version number
echo "$version_number"
elif [ "$2" = "-v" ] || [ "$2" = "--version" ]; then
# Print just the version number
echo "$version_number"
elif [ "$2" = "-p" ] || [ "$2" = "--path-version" ]; then
# Print the concatenation of the path and the version
echo "$path_version"
else
echo "Invalid option: '$2'"
exit 1
fi