Skip to content

Commit

Permalink
Merge pull request #4 from blbynum/release/1.1.2
Browse files Browse the repository at this point in the history
Release/1.1.2
  • Loading branch information
blbynum authored Jun 5, 2023
2 parents 78608e7 + d896c44 commit 1392c72
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 14 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ Creates a new profile with the specified name and load order.
prof create <profile_name> <load_order>
```

### edit <profile_name>
### edit <profile_name> [new_load_order]

Opens an existing profile in your preferred text editor for editing.
Opens an existing profile in your preferred text editor for editing. Optionally, you can update the load order of the profile by providing a new load order as the second argument.

```shell
prof edit <profile_name>
prof edit <profile_name> [new_load_order]
```

### delete <profile_name>
Expand Down
47 changes: 36 additions & 11 deletions prof
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# Ben Bynum
#
# Version:
# 1.1.1
# 1.1.2
# 06/04/2023
#
# Repository:
Expand Down Expand Up @@ -160,17 +160,40 @@ function create_profile {
function edit_profile {
if [ -z "$1" ]; then
echo "Error: No profile name provided."
echo "Usage: prof edit <profile_name>"
echo "Usage: prof edit <profile_name> [new_load_order]"
return 1
fi

local profile_name=$1
local new_load_order=$2

# Check if the new load order is a positive integer if provided
if [[ -n "$new_load_order" && ! "$new_load_order" =~ ^[0-9]+$ ]]; then
echo "Error: Load order must be a positive integer."
return 1
fi

# Determine the user's preferred editor
local editor=${EDITOR:-vi} # Default to vi if no editor is set

# Check if the profile exists
if grep -qw "$profile_name" ~/.bash_profiles/.profile_metadata; then
# If a new load order is provided, update it
if [ -n "$new_load_order" ]; then
# Format the new load order with leading zeros
printf -v formatted_load_order "%02d" "$new_load_order"

# Identify the OS
case "$(uname -s)" in
Darwin*) sed -i '' "s/^.*$profile_name$/$formatted_load_order $profile_name/" ~/.bash_profiles/.profile_metadata ;;
Linux*) sed -i "s/^.*$profile_name$/$formatted_load_order $profile_name/" ~/.bash_profiles/.profile_metadata ;;
*) echo "Unsupported OS" ;;
esac

# Sort the metadata file by load order
sort ~/.bash_profiles/.profile_metadata -o ~/.bash_profiles/.profile_metadata
fi

# Open the profile in the editor
$editor ~/.bash_profiles/$profile_name
else
Expand All @@ -179,6 +202,8 @@ function edit_profile {
fi
}



function delete_profile {
if [ -z "$1" ]; then
echo "Error: No profile name provided."
Expand Down Expand Up @@ -356,30 +381,30 @@ prof - CLI tool for managing bash profiles
Usage: prof <command> [arguments]
Commands:
create <profile_name> <load_order> Create a new profile
edit <profile_name> Edit an existing profile
delete <profile_name> Delete an existing profile
list List all profiles
create <profile_name> <load_order> Create a new profile
edit <profile_name> [new_load_order] Edit an existing profile (optional: update load order)
delete <profile_name> Delete an existing profile
list List all profiles
export <profile_name> <export_directory> Export a profile to an export directory
import <profile_file> <load_order> Import a profile with a specific load order
install [<target_file>] Install the profile loader line in the target file
(default: ~/.bash_profile)
import <profile_file> <load_order> Import a profile with a specific load order
install [<target_file>] Install the profile loader line in the target file (default: ~/.bash_profile)
help Display this help message
help Display this help message
Note: The 'install' command installs the line to load profiles in the target file,
such as ~/.bash_profile. You can specify a different file by providing
an optional argument, e.g., prof install .zshrc.
EOF
}


function main {
case "$1" in
create)
create_profile "$2" "$3"
;;
edit)
edit_profile "$2"
edit_profile "$2" "$3"
;;
delete)
delete_profile "$2"
Expand Down

0 comments on commit 1392c72

Please sign in to comment.