forked from Rickfdalton/aliases-and-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopen-issue
42 lines (35 loc) · 1.09 KB
/
open-issue
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
#!/bin/bash
# This script creates a folder structure for an issue and opens the corresponding folder in a file manager.
# Usage: open-issue ISSUE-1234
# Set the base folder path here
BASE_FOLDER="/Users/username/Desktop/TICKETS"
# Check if the issue name is provided as an argument
if [ -z "$1" ]; then
echo "Usage: $0 ISSUE-1234"
exit 1
fi
# Extract issue details
ISSUE_NAME="$1"
ISSUE_FOLDER="${BASE_FOLDER}/${ISSUE_NAME%%-*}" # Extracts the portion before the first hyphen
SUBFOLDER="${ISSUE_FOLDER}/${ISSUE_NAME}"
# Create the main issue folder if it doesn't exist
if [ ! -d "$ISSUE_FOLDER" ]; then
mkdir -p "$ISSUE_FOLDER"
fi
# Create the subfolder if it doesn't exist
if [ ! -d "$SUBFOLDER" ]; then
mkdir -p "$SUBFOLDER"
fi
# Navigate to the subfolder
cd "$SUBFOLDER" || {
echo "Failed to navigate to $SUBFOLDER"
exit 1
}
# Open the folder using the appropriate file manager
if command -v open &> /dev/null; then
open .
elif command -v xdg-open &> /dev/null; then
xdg-open .
else
echo "Unable to open file manager. Please open the folder manually: $SUBFOLDER"
fi