This commit is contained in:
kumar vaibhav 2025-11-21 20:01:07 +05:30
parent 980b1c01a8
commit d59a4fe592
2 changed files with 79 additions and 34 deletions

View file

@ -99,11 +99,11 @@ last_switch = null
[packages] [packages]
# List of packages to install using dnf # List of packages to install using dnf
# Set to true to install, false or comment out to skip # Just list package names - presence means install, absence means don't install
git = true git
vim = true vim
curl = true curl
wget = true wget
[dotfiles] [dotfiles]
# Dotfiles to manage with symlinks # Dotfiles to manage with symlinks
@ -127,7 +127,20 @@ backup_dir = "backup"
- `last_switch`: Timestamp of last switch operation (auto-updated) - `last_switch`: Timestamp of last switch operation (auto-updated)
#### `[packages]` #### `[packages]`
List of packages to install via dnf. Set to `true` to install, `false` or comment out to skip. List of packages to install via dnf. **Just list package names** - presence means install, absence means don't install.
**Examples:**
```toml
[packages]
git
vim
curl
wget
nodejs
npm
```
To remove a package, simply delete the line containing the package name.
#### `[dotfiles]` #### `[dotfiles]`
Dotfile mappings using symlinks: Dotfile mappings using symlinks:
@ -155,6 +168,12 @@ Additional configuration options:
## How It Works ## How It Works
### Package Management
Packages are managed through the `[packages]` section in `forge.toml`:
- **Add package**: Simply add the package name on a new line
- **Remove package**: Delete the line containing the package name
- **No flags needed**: Just presence/absence of the package name matters
### Dotfile Management ### Dotfile Management
Forge uses symlinks to manage dotfiles: Forge uses symlinks to manage dotfiles:
1. Your actual dotfiles are stored in `~/.config/forge/dotfiles/` 1. Your actual dotfiles are stored in `~/.config/forge/dotfiles/`
@ -162,12 +181,6 @@ Forge uses symlinks to manage dotfiles:
3. This allows you to version control your dotfiles in one place 3. This allows you to version control your dotfiles in one place
4. Changes to the source files are immediately reflected in your home directory 4. Changes to the source files are immediately reflected in your home directory
### Package Management
Packages are managed through the `[packages]` section in `forge.toml`:
- Packages set to `true` are installed via `dnf`
- Packages set to `false` or commented out are ignored
- No automatic uninstallation (unlike the previous version)
### Backup System ### Backup System
Before creating symlinks, Forge: Before creating symlinks, Forge:
1. Checks if the target file exists and is not a symlink 1. Checks if the target file exists and is not a symlink
@ -182,16 +195,17 @@ Before creating symlinks, Forge:
# Initialize forge # Initialize forge
./forge init ./forge init
# Create your dotfiles directory and add files # Edit forge.toml to add packages
mkdir -p ~/.config/forge/dotfiles
echo "export EDITOR=vim" > ~/.config/forge/dotfiles/.bashrc
# Edit forge.toml to configure
nano ~/.config/forge/forge.toml nano ~/.config/forge/forge.toml
# Add to [packages] section: # Add to [packages] section:
git = true git
vim = true vim
curl
# Create your dotfiles directory and add files
mkdir -p ~/.config/forge/dotfiles
echo "export EDITOR=vim" > ~/.config/forge/dotfiles/.bashrc
# Add to [dotfiles] section: # Add to [dotfiles] section:
".bashrc" = "dotfiles/.bashrc" ".bashrc" = "dotfiles/.bashrc"
@ -216,6 +230,25 @@ nano ~/.config/forge/forge.toml
./forge switch ./forge switch
``` ```
### Package Management Examples
```toml
[packages]
# Development tools
git
vim
nodejs
npm
# System utilities
curl
wget
tree
htop
# To remove a package, just delete the line
# For example, to remove htop, delete the "htop" line
```
### Version Control Your Configuration ### Version Control Your Configuration
```bash ```bash
# Initialize git repository in forge directory # Initialize git repository in forge directory
@ -240,11 +273,22 @@ git commit -m "Updated vim configuration"
## Migration from Previous Version ## Migration from Previous Version
If you were using the old version of forge: If you were using the old version of forge with `git = true` format:
1. Your existing configuration will not be automatically migrated 1. Your existing configuration will not be automatically migrated
2. Run `./forge init` to create the new `forge.toml` structure 2. Run `./forge init` to create the new `forge.toml` structure
3. Manually migrate your packages and dotfile configurations to the new TOML format 3. Convert your package configuration from:
```toml
# Old format
git = true
vim = true
```
to:
```toml
# New format
git
vim
```
4. Move your existing dotfiles from the old directory to `~/.config/forge/dotfiles/` 4. Move your existing dotfiles from the old directory to `~/.config/forge/dotfiles/`
## License ## License

27
forge
View file

@ -52,10 +52,11 @@ last_switch = null
[packages] [packages]
# List of packages to install using dnf # List of packages to install using dnf
# Just list package names - presence means install, absence means don't install
# Examples: # Examples:
# git = true # git
# vim = true # vim
# curl = true # curl
[dotfiles] [dotfiles]
# Dotfiles to manage with symlinks # Dotfiles to manage with symlinks
@ -92,11 +93,15 @@ parse_toml() {
continue continue
fi fi
# Parse key-value pairs # Parse key-value pairs for non-packages sections
if [[ "$line" =~ ^([^=]+)=(.+)$ ]]; then if [[ "$section" != "packages" && "$line" =~ ^([^=]+)=(.+)$ ]]; then
local key="${BASH_REMATCH[1]// /}" local key="${BASH_REMATCH[1]// /}"
local value="${BASH_REMATCH[2]// /}" local value="${BASH_REMATCH[2]// /}"
echo "$section:$key=$value" echo "$section:$key=$value"
# Parse package names (just keys without values in packages section)
elif [[ "$section" == "packages" && "$line" =~ ^([^=]+)$ ]]; then
local package="${BASH_REMATCH[1]// /}"
echo "$section:$package"
fi fi
done <"$FORGE_TOML" done <"$FORGE_TOML"
} }
@ -109,11 +114,9 @@ install_packages() {
while IFS='=' read -r entry; do while IFS='=' read -r entry; do
local section="${entry%%:*}" local section="${entry%%:*}"
local key_value="${entry#*:}" local package="${entry#*:}"
local package="${key_value%%=*}"
local enabled="${key_value##*=}"
if [[ "$section" == "packages" && "$enabled" == "true" ]]; then if [[ "$section" == "packages" && -n "$package" ]]; then
packages_installed=true packages_installed=true
log_info "Installing package: $package" log_info "Installing package: $package"
if sudo dnf install -y "$package"; then if sudo dnf install -y "$package"; then
@ -228,11 +231,9 @@ status() {
local package_count=0 local package_count=0
while IFS='=' read -r entry; do while IFS='=' read -r entry; do
local section="${entry%%:*}" local section="${entry%%:*}"
local key_value="${entry#*:}" local package="${entry#*:}"
local package="${key_value%%=*}"
local enabled="${key_value##*=}"
if [[ "$section" == "packages" && "$enabled" == "true" ]]; then if [[ "$section" == "packages" && -n "$package" ]]; then
echo " $package" echo " $package"
((package_count++)) ((package_count++))
fi fi