Compare commits
13 Commits
a7f7452b2b
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ee72ede116 | ||
|
|
f5244ac062 | ||
|
|
9a089112c3 | ||
|
|
e64a857a43 | ||
|
|
ddd7d4193a | ||
|
|
83a1c8ce48 | ||
|
|
b29fa3b30c | ||
|
|
cd0bcfd214 | ||
|
|
a91c41871a | ||
|
|
9698f0e506 | ||
|
|
9e22f007b9 | ||
|
|
d472fb61aa | ||
|
|
9108ee8266 |
35
README.md
35
README.md
@@ -10,12 +10,28 @@ current shell is not bash.
|
|||||||
|
|
||||||
## 2. Getting started
|
## 2. Getting started
|
||||||
Download and extract (or use git clone) the profile archive into your home
|
Download and extract (or use git clone) the profile archive into your home
|
||||||
directory. You will have to modify your `~/.bashrc` and/or `~/.profile` file to
|
directory.
|
||||||
add at the end (preferably):
|
|
||||||
|
The profile is designed to be **sourced**, not executed directly.
|
||||||
|
|
||||||
|
Manual setup:
|
||||||
```bash
|
```bash
|
||||||
source <installpath>/profile/profile.sh
|
source <installpath>/profile/profile.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Automatic setup (recommended):
|
||||||
|
```bash
|
||||||
|
bash <installpath>/profile/profile.sh --install
|
||||||
|
```
|
||||||
|
|
||||||
|
`--install` appends the required `source` line to both `~/.bashrc` and
|
||||||
|
`~/.profile` by default. You can target one file only:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
bash <installpath>/profile/profile.sh --install --bashrc
|
||||||
|
bash <installpath>/profile/profile.sh --install --profile
|
||||||
|
```
|
||||||
|
|
||||||
You may also set the `PROFILE_PATH` environment variable before sourcing if you
|
You may also set the `PROFILE_PATH` environment variable before sourcing if you
|
||||||
want to override the automatic path detection:
|
want to override the automatic path detection:
|
||||||
```bash
|
```bash
|
||||||
@@ -49,10 +65,10 @@ A bar-style prompt showing current time, execution time of the last command
|
|||||||
| Function | Module | Description |
|
| Function | Module | Description |
|
||||||
|---|---|---|
|
|---|---|---|
|
||||||
| `busy` | fun | Monitor /dev/urandom for a hex pattern — look busy |
|
| `busy` | fun | Monitor /dev/urandom for a hex pattern — look busy |
|
||||||
| `check_updates` | updates | Check whether a newer profile version is available online |
|
| `check_updates` | updates | Check whether a newer profile version is available online; when called with `-q` at startup a 3-second network timeout is applied so a slow or absent network never delays the prompt |
|
||||||
| `clean` | filefct | Erase backup files in given directories, optionally recursive |
|
| `clean` | filefct | Erase backup files in given directories, optionally recursive |
|
||||||
| `disp` | disp | Display formatted info / warning / error / debug messages |
|
| `disp` | disp | Display formatted info / warning / error / debug messages; long messages are word-wrapped and continuation lines are indented to align with the message text |
|
||||||
| `dwl` | net | Download a URL using curl, wget, or fetch transparently |
|
| `dwl` | net | Download a URL using curl, wget, or fetch transparently; supports `-t <seconds>` / `--timeout <seconds>` to cap the transfer time |
|
||||||
| `expandlist` | filefct | Expand glob expressions into a quoted, separated list |
|
| `expandlist` | filefct | Expand glob expressions into a quoted, separated list |
|
||||||
| `file_stats` | filefct | Display file size statistics for a path |
|
| `file_stats` | filefct | Display file size statistics for a path |
|
||||||
| `findbig` | filefct | Find the biggest files in the given or current directory |
|
| `findbig` | filefct | Find the biggest files in the given or current directory |
|
||||||
@@ -68,7 +84,7 @@ A bar-style prompt showing current time, execution time of the last command
|
|||||||
| `gsync` | git | Fetch and rebase the current branch onto its upstream |
|
| `gsync` | git | Fetch and rebase the current branch onto its upstream |
|
||||||
| `gst` | git | Display compact git status with branch tracking information |
|
| `gst` | git | Display compact git status with branch tracking information |
|
||||||
| `gwip` | git | Create a quick WIP checkpoint commit |
|
| `gwip` | git | Create a quick WIP checkpoint commit |
|
||||||
| `help` | help | Display the list of available functions and basic usage |
|
| `help` | help | Display the list of available functions and basic usage; `help <command>` delegates to `<command> --help` |
|
||||||
| `isipv4` | net | Tell if the given parameter is a valid IPv4 address |
|
| `isipv4` | net | Tell if the given parameter is a valid IPv4 address |
|
||||||
| `isipv6` | net | Tell if the given parameter is a valid IPv6 address |
|
| `isipv6` | net | Tell if the given parameter is a valid IPv6 address |
|
||||||
| `ku` | processes | Kill all processes owned by the given user name or ID |
|
| `ku` | processes | Kill all processes owned by the given user name or ID |
|
||||||
@@ -99,6 +115,13 @@ A bar-style prompt showing current time, execution time of the last command
|
|||||||
Locale shortcut functions (`setfr`, `setus`, etc.) are dynamically generated at
|
Locale shortcut functions (`setfr`, `setus`, etc.) are dynamically generated at
|
||||||
startup from the `SET_LOCALE` configuration key (see section 4).
|
startup from the `SET_LOCALE` configuration key (see section 4).
|
||||||
|
|
||||||
|
### 3.3. Bash completion
|
||||||
|
|
||||||
|
profile loads all `*.sh` files found under `profile.d/bash-completion/`
|
||||||
|
automatically in interactive sessions. This directory is the right place to add
|
||||||
|
any custom completion definitions. profile already ships completions for its git
|
||||||
|
helper functions there (`git-completion.sh`).
|
||||||
|
|
||||||
## 4. Configuration
|
## 4. Configuration
|
||||||
profile uses an INI-style configuration file (`profile.conf`) located in the
|
profile uses an INI-style configuration file (`profile.conf`) located in the
|
||||||
same directory as `profile.sh`. Sections are declared with `[section_name]` and
|
same directory as `profile.sh`. Sections are declared with `[section_name]` and
|
||||||
|
|||||||
@@ -7,6 +7,31 @@ Versions follow `MAJOR.MINOR.PATCH-REVISION_STAGE_N` (e.g. `3.99.1-4_rc_1`).
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## [4.1.0] — 2026-05-07
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- `profile.sh --install` command to automatically configure profile loading in
|
||||||
|
shell startup files.
|
||||||
|
- `--install --bashrc` and `--install --profile` target selectors for
|
||||||
|
single-file installation.
|
||||||
|
- **`git.sh`** — entirely new module providing git workflow helpers: `gst`,
|
||||||
|
`ggraph`, `gsync`, `gacp`, `greset`, `gwip`, `gprune`, `groot`.
|
||||||
|
- Dedicated git helper completions under `profile.d/bash-completion/`, loaded
|
||||||
|
automatically in interactive sessions from `profile.d/bash-completion/*.sh`.
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- `disp` now wraps long messages on terminal width, avoids mid-word splits, and
|
||||||
|
aligns continuation lines with the message body after the prefix.
|
||||||
|
- `help` now supports `help <command>` and delegates to `<command> --help`.
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Startup responsiveness improved: `check_updates -q` now uses a short network
|
||||||
|
timeout so unavailable/slow networks no longer delay prompt readiness.
|
||||||
|
- `dwl` gained timeout support (`-t` / `--timeout`) and is now used by quiet
|
||||||
|
startup update checks to enforce fast failure.
|
||||||
|
- `profile.sh` now detects direct execution and warns that it is designed to be
|
||||||
|
sourced.
|
||||||
|
|
||||||
## [4.0.0] — 2026-04-23
|
## [4.0.0] — 2026-04-23
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|||||||
120
doc/FAQ.md
120
doc/FAQ.md
@@ -4,6 +4,33 @@
|
|||||||
|
|
||||||
## Installation & loading
|
## Installation & loading
|
||||||
|
|
||||||
|
**Q: How do I install profile automatically into my shell startup files?**
|
||||||
|
|
||||||
|
Run the installer directly (no need to source first):
|
||||||
|
```bash
|
||||||
|
bash <installpath>/profile/profile.sh --install
|
||||||
|
```
|
||||||
|
This appends the required `source` line to both `~/.bashrc` and `~/.profile`.
|
||||||
|
To target only one file:
|
||||||
|
```bash
|
||||||
|
bash <installpath>/profile/profile.sh --install --bashrc
|
||||||
|
bash <installpath>/profile/profile.sh --install --profile
|
||||||
|
```
|
||||||
|
The operation is idempotent — running it again will not add a duplicate line.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Q: I ran `profile.sh` directly and got a warning about sourcing.**
|
||||||
|
|
||||||
|
profile.sh is designed to be *sourced*, not executed:
|
||||||
|
```bash
|
||||||
|
source <installpath>/profile/profile.sh
|
||||||
|
```
|
||||||
|
The only exception is `--install`, which must be passed to a direct execution
|
||||||
|
(`bash profile.sh --install`) to set up the sourcing line automatically.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
**Q: profile refuses to load and prints "This profile requires Bash 4.3 or higher."**
|
**Q: profile refuses to load and prints "This profile requires Bash 4.3 or higher."**
|
||||||
|
|
||||||
Your system's default shell is an older Bash (common on macOS, which ships
|
Your system's default shell is an older Bash (common on macOS, which ships
|
||||||
@@ -84,7 +111,8 @@ Add to `profile.conf`:
|
|||||||
PROMPT_THEME = dark
|
PROMPT_THEME = dark
|
||||||
```
|
```
|
||||||
Built-in names: `default`, `dark`, `light`, `solarized`, `solarized-light`,
|
Built-in names: `default`, `dark`, `light`, `solarized`, `solarized-light`,
|
||||||
`monokai`, `monochrome`, `abyss`, `plasma`, `adwaita`.
|
`monokai`, `monochrome`, `abyss`, `plasma`, `adwaita`, but you can create your
|
||||||
|
own theme.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -119,6 +147,55 @@ theme file cannot execute code. Values must be a colour variable reference
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## Git helpers
|
||||||
|
|
||||||
|
**Q: What git helper functions does profile provide?**
|
||||||
|
|
||||||
|
All git helpers are defined in `profile.d/git.sh` (new in 4.1.0):
|
||||||
|
|
||||||
|
| Command | Purpose |
|
||||||
|
|---|---|
|
||||||
|
| `gst` | Compact status with branch tracking info |
|
||||||
|
| `ggraph` | Decorated history graph |
|
||||||
|
| `gsync` | Fetch and rebase onto upstream |
|
||||||
|
| `gacp` | Add, commit and push in one command |
|
||||||
|
| `greset` | Reset to upstream, stashing local changes first |
|
||||||
|
| `gwip` | Quick WIP checkpoint commit |
|
||||||
|
| `gprune` | Delete merged local branches |
|
||||||
|
| `groot` | Print or cd to repository root |
|
||||||
|
|
||||||
|
All commands accept `-h` / `--help`.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Q: Tab completion for `gacp` does not show modified files.**
|
||||||
|
|
||||||
|
Profile ships dedicated completions in `profile.d/bash-completion/git-completion.sh`,
|
||||||
|
loaded automatically in interactive sessions. If completions are missing,
|
||||||
|
check that the system git completion is installed:
|
||||||
|
```bash
|
||||||
|
# Debian / Ubuntu
|
||||||
|
apt-get install bash-completion
|
||||||
|
# Fedora / RHEL
|
||||||
|
dnf install bash-completion
|
||||||
|
```
|
||||||
|
When the native git completion helpers are available, `gacp` path completion
|
||||||
|
behaves exactly like `git add` (modified files, untracked files, directories).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Q: `gacp` says "No files specified" even though I passed `-a`.**
|
||||||
|
|
||||||
|
The `-a` / `--auto` flag adds all modified files (equivalent to `git add -A`).
|
||||||
|
The default depends on `GIT_GACP_AUTO_ADD` in `profile.conf`:
|
||||||
|
```ini
|
||||||
|
[git]
|
||||||
|
GIT_GACP_AUTO_ADD = 1
|
||||||
|
```
|
||||||
|
Set to `1` to make `-a` the default.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## Functions
|
## Functions
|
||||||
|
|
||||||
**Q: `meteo` prints "No city specified" even though I set a default.**
|
**Q: `meteo` prints "No city specified" even though I set a default.**
|
||||||
@@ -147,11 +224,46 @@ Or set `DWL_PREFERRED_TOOL` in `[net]` to whichever tool you have.
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
**Q: How do I limit how long `dwl` waits for a download?**
|
||||||
|
|
||||||
|
Use the `-t` / `--timeout` option:
|
||||||
|
```bash
|
||||||
|
dwl -t 5 https://example.com/file.txt /tmp/file.txt
|
||||||
|
```
|
||||||
|
This sets a 5-second cap on both the connection and the overall transfer.
|
||||||
|
The timeout is propagated to `curl` (`--max-time` + `--connect-timeout`),
|
||||||
|
`wget` (`--timeout`), or `fetch` (`-T`) transparently.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Q: The prompt takes a long time to appear when my network is unavailable.**
|
||||||
|
|
||||||
|
Fixed in 4.1.0. `check_updates -q` (called at startup) now enforces a
|
||||||
|
3-second network timeout. If the update server is unreachable the check
|
||||||
|
fails silently and the prompt appears immediately.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Q: `help` only shows a list of functions. Can I get usage for a specific one?**
|
||||||
|
|
||||||
|
Yes — pass the command name as an argument:
|
||||||
|
```bash
|
||||||
|
help gacp
|
||||||
|
help dwl
|
||||||
|
help taz
|
||||||
|
```
|
||||||
|
This calls `<command> --help` and prints the full usage for that function.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
**Q: `pkgs` does not find packages I know are installed.**
|
**Q: `pkgs` does not find packages I know are installed.**
|
||||||
|
|
||||||
`pkgs` delegates to `dpkg -l` (Debian/Ubuntu) or `rpm -qa` (RHEL/Fedora).
|
`pkgs` uses `get_pkgmgr` to detect the active package manager and delegates
|
||||||
If your distribution uses a different package manager (pacman, apk, brew …)
|
to the appropriate tool. Supported families: `apt` (Debian/Ubuntu),
|
||||||
it is not yet supported. See `doc/todo.md` for the tracking issue.
|
`dnf` / `yum` (RHEL/Fedora), `zypper` (openSUSE), `pacman` (Arch),
|
||||||
|
`apk` (Alpine), `portage` (Gentoo), `xbps` (Void), `nix`, `brew` (macOS).
|
||||||
|
If your distribution is not detected, run `get_pkgmgr` to see what is
|
||||||
|
identified, and check that the package manager binary is in your `PATH`.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ version-bump.
|
|||||||
blockers are `local -A` (no associative arrays in ZSH without `typeset -A`)
|
blockers are `local -A` (no associative arrays in ZSH without `typeset -A`)
|
||||||
and `local -n` namerefs. A thin compatibility shim would open the project to
|
and `local -n` namerefs. A thin compatibility shim would open the project to
|
||||||
ZSH users. **[hard]**
|
ZSH users. **[hard]**
|
||||||
- [ ] **Bash completion** — add a `profile.d/completion/` directory and write
|
- [ ] **Bash completion** — add a more bash completion directory and write
|
||||||
`_profile_upgrade`, `_taz`, `_utaz`, `_meteo`, etc. completions so that
|
`_profile_upgrade`, `_taz`, `_utaz`, `_meteo`, etc. completions so that
|
||||||
`<Tab>` works on all public functions. **[medium]**
|
`<Tab>` works on all public functions. **[medium]**
|
||||||
|
|
||||||
|
|||||||
220
profile.d/bash-completion/git-completion.sh
Normal file
220
profile.d/bash-completion/git-completion.sh
Normal file
@@ -0,0 +1,220 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
# Git helper completions for profile.d/git.sh shortcuts.
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
# Return 0 when current directory is inside a git work tree.
|
||||||
|
_profile_git_in_repo()
|
||||||
|
{
|
||||||
|
git rev-parse --is-inside-work-tree >/dev/null 2>&1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Load git completion helpers on demand if they are available on the system.
|
||||||
|
_profile_git_load_completion_helpers()
|
||||||
|
{
|
||||||
|
declare -F __git_complete >/dev/null 2>&1 && return 0
|
||||||
|
|
||||||
|
local completion_file
|
||||||
|
for completion_file in \
|
||||||
|
/usr/share/bash-completion/completions/git \
|
||||||
|
/usr/share/git/completion/git-completion.bash \
|
||||||
|
/etc/bash_completion.d/git
|
||||||
|
do
|
||||||
|
if [[ -r "$completion_file" ]]; then
|
||||||
|
# shellcheck source=/dev/null
|
||||||
|
. "$completion_file"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
declare -F __git_complete >/dev/null 2>&1
|
||||||
|
}
|
||||||
|
|
||||||
|
_profile_git_complete_remotes()
|
||||||
|
{
|
||||||
|
local cur
|
||||||
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||||
|
|
||||||
|
if ! _profile_git_in_repo; then
|
||||||
|
COMPREPLY=()
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
COMPREPLY=( $(compgen -W "$(git remote 2>/dev/null)" -- "$cur") )
|
||||||
|
}
|
||||||
|
|
||||||
|
_profile_git_complete_refs()
|
||||||
|
{
|
||||||
|
local cur
|
||||||
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||||
|
|
||||||
|
if ! _profile_git_in_repo; then
|
||||||
|
COMPREPLY=()
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
COMPREPLY=( $(compgen -W "$(git for-each-ref --format='%(refname:short)' refs/heads refs/remotes refs/tags 2>/dev/null)" -- "$cur") )
|
||||||
|
}
|
||||||
|
|
||||||
|
_profile_git_complete_add_paths()
|
||||||
|
{
|
||||||
|
# shellcheck disable=SC2034 # Used indirectly by git-completion helpers via dynamic scope.
|
||||||
|
local cur words cword prev __git_cmd_idx=0
|
||||||
|
local complete_opt="--others --modified --directory --no-empty-directory"
|
||||||
|
|
||||||
|
if declare -F __git_complete_index_file >/dev/null 2>&1; then
|
||||||
|
if declare -F _get_comp_words_by_ref >/dev/null 2>&1; then
|
||||||
|
_get_comp_words_by_ref -n =: cur words cword prev
|
||||||
|
else
|
||||||
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||||
|
if (( COMP_CWORD > 0 )); then
|
||||||
|
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||||||
|
else
|
||||||
|
prev=""
|
||||||
|
fi
|
||||||
|
# shellcheck disable=SC2034 # Used indirectly by git-completion helpers via dynamic scope.
|
||||||
|
cword="$COMP_CWORD"
|
||||||
|
# shellcheck disable=SC2034 # Used indirectly by git-completion helpers via dynamic scope.
|
||||||
|
words=("${COMP_WORDS[@]}")
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -n $(__git_find_on_cmdline "-u --update") ]]; then
|
||||||
|
complete_opt="--modified"
|
||||||
|
fi
|
||||||
|
__git_complete_index_file "$complete_opt"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
COMPREPLY=( $(compgen -f -- "${COMP_WORDS[COMP_CWORD]}") )
|
||||||
|
}
|
||||||
|
|
||||||
|
_complete_gst()
|
||||||
|
{
|
||||||
|
local cur
|
||||||
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||||
|
|
||||||
|
case "$cur" in
|
||||||
|
-*)
|
||||||
|
COMPREPLY=( $(compgen -W "-h --help" -- "$cur") )
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
COMPREPLY=( $(compgen -d -- "$cur") )
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
_complete_ggraph()
|
||||||
|
{
|
||||||
|
local cur prev
|
||||||
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||||
|
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||||||
|
|
||||||
|
case "$prev" in
|
||||||
|
-n|--limit)
|
||||||
|
COMPREPLY=()
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
COMPREPLY=( $(compgen -W "-h --help -n --limit" -- "$cur") )
|
||||||
|
}
|
||||||
|
|
||||||
|
_complete_gsync()
|
||||||
|
{
|
||||||
|
local cur
|
||||||
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||||
|
|
||||||
|
if [[ $cur == -* ]]; then
|
||||||
|
COMPREPLY=( $(compgen -W "-h --help" -- "$cur") )
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
_profile_git_complete_remotes
|
||||||
|
}
|
||||||
|
|
||||||
|
_complete_gacp()
|
||||||
|
{
|
||||||
|
local cur prev
|
||||||
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||||
|
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||||||
|
|
||||||
|
case "$prev" in
|
||||||
|
-m|--message)
|
||||||
|
COMPREPLY=()
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if [[ $cur == -* ]]; then
|
||||||
|
COMPREPLY=( $(compgen -W "-h --help -a --auto -m --message" -- "$cur") )
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
_profile_git_complete_add_paths
|
||||||
|
}
|
||||||
|
|
||||||
|
_complete_greset()
|
||||||
|
{
|
||||||
|
local cur
|
||||||
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||||
|
|
||||||
|
if [[ $cur == -* ]]; then
|
||||||
|
COMPREPLY=( $(compgen -W "-h --help -x --with-ignored" -- "$cur") )
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
_profile_git_complete_refs
|
||||||
|
}
|
||||||
|
|
||||||
|
_complete_gwip()
|
||||||
|
{
|
||||||
|
local cur
|
||||||
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||||
|
|
||||||
|
if [[ $cur == -* ]]; then
|
||||||
|
COMPREPLY=( $(compgen -W "-h --help" -- "$cur") )
|
||||||
|
else
|
||||||
|
COMPREPLY=()
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
_complete_gprune()
|
||||||
|
{
|
||||||
|
local cur
|
||||||
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||||
|
|
||||||
|
if [[ $cur == -* ]]; then
|
||||||
|
COMPREPLY=( $(compgen -W "-h --help" -- "$cur") )
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
_profile_git_complete_refs
|
||||||
|
}
|
||||||
|
|
||||||
|
_complete_groot()
|
||||||
|
{
|
||||||
|
local cur
|
||||||
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||||
|
|
||||||
|
COMPREPLY=( $(compgen -W "-h --help -g --go" -- "$cur") )
|
||||||
|
}
|
||||||
|
|
||||||
|
_profile_git_register_completions()
|
||||||
|
{
|
||||||
|
complete -F _complete_gst gst
|
||||||
|
complete -F _complete_ggraph ggraph
|
||||||
|
complete -F _complete_gsync gsync
|
||||||
|
complete -F _complete_gacp gacp
|
||||||
|
complete -F _complete_greset greset
|
||||||
|
complete -F _complete_gwip gwip
|
||||||
|
complete -F _complete_gprune gprune
|
||||||
|
complete -F _complete_groot groot
|
||||||
|
}
|
||||||
|
|
||||||
|
# Register completions only in interactive bash sessions.
|
||||||
|
if [[ $- == *i* && -n ${BASH_VERSION:-} ]]; then
|
||||||
|
_profile_git_load_completion_helpers >/dev/null 2>&1 || true
|
||||||
|
_profile_git_register_completions
|
||||||
|
fi
|
||||||
|
|
||||||
|
# EOF
|
||||||
@@ -476,7 +476,7 @@ taz()
|
|||||||
[[ $4 ]] && opt=('--verbose')
|
[[ $4 ]] && opt=('--verbose')
|
||||||
opt+=("$procopt")
|
opt+=("$procopt")
|
||||||
|
|
||||||
# Compresse au format bz2
|
# Compress with gzip
|
||||||
$command "${opt[@]}" --keep "-$3" "$1"
|
$command "${opt[@]}" --keep "-$3" "$1"
|
||||||
return $?
|
return $?
|
||||||
}
|
}
|
||||||
@@ -520,7 +520,7 @@ taz()
|
|||||||
[[ $4 ]] && verb=('-v')
|
[[ $4 ]] && verb=('-v')
|
||||||
[[ $2 -gt 1 ]] && disp W "lzop doesn't support multithreading, falling back to 1 thread."
|
[[ $2 -gt 1 ]] && disp W "lzop doesn't support multithreading, falling back to 1 thread."
|
||||||
|
|
||||||
# Compresse au format lzo
|
# Compress with lzo
|
||||||
lzop "${verb[@]}" --keep "-$3" "$1"
|
lzop "${verb[@]}" --keep "-$3" "$1"
|
||||||
return $?
|
return $?
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -128,52 +128,107 @@ export -f set_colors
|
|||||||
# D : debug (cyan)
|
# D : debug (cyan)
|
||||||
disp()
|
disp()
|
||||||
{
|
{
|
||||||
|
_disp_print_wrapped()
|
||||||
|
{
|
||||||
|
local prefix="$1"
|
||||||
|
local prefix_len="$2"
|
||||||
|
local target_fd="$3"
|
||||||
|
shift 3
|
||||||
|
local message="$*"
|
||||||
|
|
||||||
|
local cols="${COLUMNS:-}"
|
||||||
|
if [[ -z "$cols" || ! "$cols" =~ ^[0-9]+$ || "$cols" -lt 20 ]]; then
|
||||||
|
cols=$(tput cols 2>/dev/null)
|
||||||
|
fi
|
||||||
|
[[ -z "$cols" || ! "$cols" =~ ^[0-9]+$ || "$cols" -lt 20 ]] && cols=80
|
||||||
|
|
||||||
|
local indent_len=0
|
||||||
|
[[ "$prefix_len" =~ ^[0-9]+$ && "$prefix_len" -gt 0 ]] && indent_len=$((prefix_len + 1))
|
||||||
|
|
||||||
|
local width=$((cols - indent_len))
|
||||||
|
(( width < 10 )) && width=10
|
||||||
|
|
||||||
|
local wrapped
|
||||||
|
wrapped=$(printf "%s" "$message" | fold -s -w "$width")
|
||||||
|
|
||||||
|
local first_line=1
|
||||||
|
local line
|
||||||
|
while IFS= read -r line || [[ -n "$line" ]]; do
|
||||||
|
if (( first_line )); then
|
||||||
|
if [[ -n "$prefix" ]]; then
|
||||||
|
if [[ "$target_fd" -eq 2 ]]; then
|
||||||
|
printf "%b\n" "${prefix} ${line}${RESETCOL}" >&2
|
||||||
|
else
|
||||||
|
printf "%b\n" "${prefix} ${line}${RESETCOL}"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
if [[ "$target_fd" -eq 2 ]]; then
|
||||||
|
printf "%b\n" "${line}${RESETCOL}" >&2
|
||||||
|
else
|
||||||
|
printf "%b\n" "${line}${RESETCOL}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
first_line=0
|
||||||
|
else
|
||||||
|
if [[ "$target_fd" -eq 2 ]]; then
|
||||||
|
printf "%*s%b\n" "$indent_len" "" "${line}${RESETCOL}" >&2
|
||||||
|
else
|
||||||
|
printf "%*s%b\n" "$indent_len" "" "${line}${RESETCOL}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done <<< "$wrapped"
|
||||||
|
}
|
||||||
|
|
||||||
# Handle NO_COLOR: disable colors if set
|
# Handle NO_COLOR: disable colors if set
|
||||||
local color_enabled=1
|
local color_enabled=1
|
||||||
[[ -n $NO_COLOR ]] && color_enabled=0
|
[[ -n $NO_COLOR ]] && color_enabled=0
|
||||||
|
|
||||||
case ${1^^} in
|
case ${1^^} in
|
||||||
"I")
|
"I")
|
||||||
|
local heads_plain="[ info ]"
|
||||||
if [[ $color_enabled -eq 1 ]]; then
|
if [[ $color_enabled -eq 1 ]]; then
|
||||||
local heads="[ ${IGreen}info${DEFAULTFG} ]"
|
local heads="[ ${IGreen}info${DEFAULTFG} ]"
|
||||||
else
|
else
|
||||||
local heads="[ info ]"
|
local heads="$heads_plain"
|
||||||
fi
|
fi
|
||||||
shift
|
shift
|
||||||
[[ -z $QUIET || $QUIET -ne 1 ]] && \
|
[[ -z $QUIET || $QUIET -ne 1 ]] && \
|
||||||
printf "%b\n" "${heads} $*${RESETCOL}"
|
_disp_print_wrapped "$heads" "${#heads_plain}" 1 "$*"
|
||||||
;;
|
;;
|
||||||
"W")
|
"W")
|
||||||
|
local heads_plain="[ Warning ]"
|
||||||
if [[ $color_enabled -eq 1 ]]; then
|
if [[ $color_enabled -eq 1 ]]; then
|
||||||
local heads="[ ${IYellow}Warning${DEFAULTFG} ]"
|
local heads="[ ${IYellow}Warning${DEFAULTFG} ]"
|
||||||
else
|
else
|
||||||
local heads="[ Warning ]"
|
local heads="$heads_plain"
|
||||||
fi
|
fi
|
||||||
shift
|
shift
|
||||||
printf "%b\n" "${heads} $*${RESETCOL}" >&2
|
_disp_print_wrapped "$heads" "${#heads_plain}" 2 "$*"
|
||||||
;;
|
;;
|
||||||
"E")
|
"E")
|
||||||
|
local heads_plain="[ ERROR ]"
|
||||||
if [[ $color_enabled -eq 1 ]]; then
|
if [[ $color_enabled -eq 1 ]]; then
|
||||||
local heads="[ ${IRed}ERROR${DEFAULTFG} ]"
|
local heads="[ ${IRed}ERROR${DEFAULTFG} ]"
|
||||||
else
|
else
|
||||||
local heads="[ ERROR ]"
|
local heads="$heads_plain"
|
||||||
fi
|
fi
|
||||||
shift
|
shift
|
||||||
printf "%b\n" "${heads} $*${RESETCOL}" >&2
|
_disp_print_wrapped "$heads" "${#heads_plain}" 2 "$*"
|
||||||
;;
|
;;
|
||||||
"D")
|
"D")
|
||||||
|
local heads_plain="[ debug ]"
|
||||||
if [[ $color_enabled -eq 1 ]]; then
|
if [[ $color_enabled -eq 1 ]]; then
|
||||||
local heads="[ ${ICyan}debug${DEFAULTFG} ]"
|
local heads="[ ${ICyan}debug${DEFAULTFG} ]"
|
||||||
else
|
else
|
||||||
local heads="[ debug ]"
|
local heads="$heads_plain"
|
||||||
fi
|
fi
|
||||||
shift
|
shift
|
||||||
[[ -n $DEBUG && $DEBUG -gt 1 ]] && \
|
[[ -n $DEBUG && $DEBUG -gt 1 ]] && \
|
||||||
printf "%b\n" "${heads} $*${RESETCOL}"
|
_disp_print_wrapped "$heads" "${#heads_plain}" 1 "$*"
|
||||||
;;
|
;;
|
||||||
* )
|
* )
|
||||||
[[ -z $QUIET || $QUIET -ne 1 ]] && \
|
[[ -z $QUIET || $QUIET -ne 1 ]] && \
|
||||||
printf "%b\n" "$*"
|
_disp_print_wrapped "" 0 1 "$*"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,9 +36,21 @@
|
|||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Display list of commands and general informations
|
# Display list of commands and general informations
|
||||||
# Usage: help
|
# Usage: help [command]
|
||||||
help()
|
help()
|
||||||
{
|
{
|
||||||
|
# If a command name is given, delegate to its --help output.
|
||||||
|
if [[ $# -gt 0 && "$1" != "--help" && "$1" != "-h" ]]; then
|
||||||
|
local cmd="$1"
|
||||||
|
if declare -F "$cmd" >/dev/null 2>&1 || command -v "$cmd" >/dev/null 2>&1; then
|
||||||
|
"$cmd" --help
|
||||||
|
else
|
||||||
|
disp E "Unknown command: $cmd"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
# shellcheck disable=SC2154 # color code in disp.sh
|
# shellcheck disable=SC2154 # color code in disp.sh
|
||||||
# shellcheck disable=SC2059 # printf format is a color variable
|
# shellcheck disable=SC2059 # printf format is a color variable
|
||||||
printf "${BIWhite}Welcome to your profile! Here is a list of available commands:${DEFAULTCOL}\n\n"
|
printf "${BIWhite}Welcome to your profile! Here is a list of available commands:${DEFAULTCOL}\n\n"
|
||||||
|
|||||||
@@ -36,27 +36,52 @@
|
|||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Download a resource using curl, wget, or fetch.
|
# Download a resource using curl, wget, or fetch.
|
||||||
# Usage: dwl <url> [output_file]
|
# Usage: dwl [-t <seconds>] <url> [output_file]
|
||||||
dwl()
|
dwl()
|
||||||
{
|
{
|
||||||
case "$1" in
|
local timeout=""
|
||||||
--help|-h)
|
|
||||||
echo "Usage: dwl <url> [output_file]"
|
# Parse leading options before the URL.
|
||||||
echo "Downloads a resource using curl, wget, or fetch."
|
while [[ $# -gt 0 ]]; do
|
||||||
echo ""
|
case "$1" in
|
||||||
echo "Arguments:"
|
--help|-h)
|
||||||
echo " url The full URL to download (http/https/ftp)."
|
echo "Usage: dwl [-t <seconds>|--timeout <seconds>] <url> [output_file]"
|
||||||
echo " output_file (Optional) Path to save the file. If omitted, prints to stdout."
|
echo "Downloads a resource using curl, wget, or fetch."
|
||||||
return 0
|
echo ""
|
||||||
;;
|
echo "Arguments:"
|
||||||
|
echo " -t, --timeout Maximum time in seconds to wait for the transfer."
|
||||||
|
echo " url The full URL to download (http/https/ftp)."
|
||||||
|
echo " output_file (Optional) Path to save the file. If omitted, prints to stdout."
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
-t|--timeout)
|
||||||
|
[[ -z "${2:-}" || ! "${2:-}" =~ ^[0-9]+$ ]] && {
|
||||||
|
echo "Error: --timeout requires a positive integer argument." >&2
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
timeout="$2"
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
|
--)
|
||||||
|
shift
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
-*)
|
||||||
|
echo "Error: Unknown option '$1'. Try 'dwl --help'." >&2
|
||||||
|
return 1
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
case "${1:-}" in
|
||||||
"")
|
"")
|
||||||
echo "Error: URL argument is missing." >&2
|
echo "Error: URL argument is missing." >&2
|
||||||
echo "Try 'get_resource --help' for usage." >&2
|
echo "Try 'dwl --help' for usage." >&2
|
||||||
return 1
|
return 1
|
||||||
;;
|
;;
|
||||||
esac
|
|
||||||
|
|
||||||
case "$1" in
|
|
||||||
http://*|https://*|ftp://*) ;;
|
http://*|https://*|ftp://*) ;;
|
||||||
*)
|
*)
|
||||||
echo "Error: '$1' does not look like a valid URL. Must start with http://, https://, or ftp://" >&2
|
echo "Error: '$1' does not look like a valid URL. Must start with http://, https://, or ftp://" >&2
|
||||||
@@ -65,35 +90,41 @@ dwl()
|
|||||||
esac
|
esac
|
||||||
|
|
||||||
local url="$1"
|
local url="$1"
|
||||||
local output="$2"
|
local output="${2:-}"
|
||||||
|
|
||||||
# Honour preferred tool from configuration; fall back to auto-detection.
|
# Honour preferred tool from configuration; fall back to auto-detection.
|
||||||
local preferred="${DWL_PREFERRED_TOOL:-}"
|
local preferred="${DWL_PREFERRED_TOOL:-}"
|
||||||
|
|
||||||
_try_curl()
|
_try_curl()
|
||||||
{
|
{
|
||||||
|
local args=(-sL)
|
||||||
|
[[ -n "$timeout" ]] && args+=(--max-time "$timeout" --connect-timeout "$timeout")
|
||||||
if [[ -z "$output" ]]; then
|
if [[ -z "$output" ]]; then
|
||||||
curl -sL "$url"
|
curl "${args[@]}" "$url"
|
||||||
else
|
else
|
||||||
curl -sL -o "$output" "$url"
|
curl "${args[@]}" -o "$output" "$url"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
_try_wget()
|
_try_wget()
|
||||||
{
|
{
|
||||||
|
local args=(-q)
|
||||||
|
[[ -n "$timeout" ]] && args+=(--timeout="$timeout")
|
||||||
if [[ -z "$output" ]]; then
|
if [[ -z "$output" ]]; then
|
||||||
wget -qO- "$url"
|
wget "${args[@]}" -O- "$url"
|
||||||
else
|
else
|
||||||
wget -q -O "$output" "$url"
|
wget "${args[@]}" -O "$output" "$url"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
_try_fetch()
|
_try_fetch()
|
||||||
{
|
{
|
||||||
|
local args=()
|
||||||
|
[[ -n "$timeout" ]] && args+=(-T "$timeout")
|
||||||
if [[ -z "$output" ]]; then
|
if [[ -z "$output" ]]; then
|
||||||
fetch -o - "$url"
|
fetch "${args[@]}" -o - "$url"
|
||||||
else
|
else
|
||||||
fetch -o "$output" "$url"
|
fetch "${args[@]}" -o "$output" "$url"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,7 @@
|
|||||||
# checking available binaries in a fixed priority order.
|
# checking available binaries in a fixed priority order.
|
||||||
# Echoes one of: apt dnf yum zypper pacman apk portage xbps nix
|
# Echoes one of: apt dnf yum zypper pacman apk portage xbps nix
|
||||||
# Returns 1 if no known package manager could be identified.
|
# Returns 1 if no known package manager could be identified.
|
||||||
_get_pkgmgr()
|
get_pkgmgr()
|
||||||
{
|
{
|
||||||
local distro_id="" distro_like=""
|
local distro_id="" distro_like=""
|
||||||
if [[ -r /etc/os-release ]]; then
|
if [[ -r /etc/os-release ]]; then
|
||||||
@@ -56,30 +56,48 @@ _get_pkgmgr()
|
|||||||
for id in $distro_id $distro_like; do
|
for id in $distro_id $distro_like; do
|
||||||
case "${id,,}" in
|
case "${id,,}" in
|
||||||
debian|ubuntu|linuxmint|raspbian|pop|kali|elementary|zorin|neon|parrot)
|
debian|ubuntu|linuxmint|raspbian|pop|kali|elementary|zorin|neon|parrot)
|
||||||
echo "apt"; return 0 ;;
|
echo "apt"
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
fedora)
|
fedora)
|
||||||
echo "dnf"; return 0 ;;
|
echo "dnf"
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
rhel|centos|rocky|almalinux|ol|scientific|amzn)
|
rhel|centos|rocky|almalinux|ol|scientific|amzn)
|
||||||
command -v dnf >/dev/null 2>&1 && { echo "dnf"; return 0; }
|
command -v dnf >/dev/null 2>&1 && { echo "dnf"; return 0; }
|
||||||
echo "yum"; return 0 ;;
|
echo "yum"
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
opensuse*|sles|sled)
|
opensuse*|sles|sled)
|
||||||
echo "zypper"; return 0 ;;
|
echo "zypper"
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
arch|manjaro|endeavouros|garuda|artix|cachyos)
|
arch|manjaro|endeavouros|garuda|artix|cachyos)
|
||||||
echo "pacman"; return 0 ;;
|
echo "pacman"
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
alpine)
|
alpine)
|
||||||
echo "apk"; return 0 ;;
|
echo "apk"
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
gentoo)
|
gentoo)
|
||||||
echo "portage"; return 0 ;;
|
echo "portage"
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
void)
|
void)
|
||||||
echo "xbps"; return 0 ;;
|
echo "xbps"
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
nixos)
|
nixos)
|
||||||
echo "nix"; return 0 ;;
|
echo "nix"
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
# Fallback: check for binaries in priority order.
|
# Fallback: check for binaries in priority order.
|
||||||
local bin
|
local bin
|
||||||
for bin in apt-get dnf yum zypper pacman apk emerge xbps-install nix-env; do
|
for bin in apt apt-get dnf yum zypper pacman apk emerge xbps-install nix-env; do
|
||||||
command -v "$bin" >/dev/null 2>&1 && {
|
command -v "$bin" >/dev/null 2>&1 && {
|
||||||
case "$bin" in
|
case "$bin" in
|
||||||
apt-get) echo "apt" ;;
|
apt-get) echo "apt" ;;
|
||||||
@@ -94,7 +112,7 @@ _get_pkgmgr()
|
|||||||
|
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
export -f _get_pkgmgr
|
export -f get_pkgmgr
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
@@ -150,7 +168,7 @@ pkgs()
|
|||||||
(( ignore_case )) && grep_opt="-i"
|
(( ignore_case )) && grep_opt="-i"
|
||||||
|
|
||||||
local pkgmgr
|
local pkgmgr
|
||||||
pkgmgr=$(_get_pkgmgr) || {
|
pkgmgr=$(get_pkgmgr) || {
|
||||||
disp E "No usable package manager could be detected on this system."
|
disp E "No usable package manager could be detected on this system."
|
||||||
return 2
|
return 2
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -90,9 +90,14 @@ check_updates()
|
|||||||
return 4
|
return 4
|
||||||
}
|
}
|
||||||
|
|
||||||
dwl "$UPDT_URL/version" "$vfile" >/dev/null 2>&1 || {
|
# In quiet mode (startup), use a short timeout so a missing or slow network
|
||||||
|
# never blocks the interactive prompt.
|
||||||
|
local dwl_opts=()
|
||||||
|
(( quiet == 1 )) && dwl_opts+=(-t 3)
|
||||||
|
|
||||||
|
dwl "${dwl_opts[@]}" "$UPDT_URL/version" "$vfile" >/dev/null 2>&1 || {
|
||||||
rm -f "$vfile"
|
rm -f "$vfile"
|
||||||
disp E "Cannot download version file; unable to continue."
|
(( quiet != 1 )) && disp E "Cannot download version file; unable to continue."
|
||||||
return 5
|
return 5
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
129
profile.sh
129
profile.sh
@@ -35,10 +35,123 @@
|
|||||||
# * OF SUCH DAMAGE.
|
# * OF SUCH DAMAGE.
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
_profile_is_sourced()
|
||||||
|
{
|
||||||
|
[[ "${BASH_SOURCE[0]}" != "$0" ]]
|
||||||
|
}
|
||||||
|
|
||||||
|
_profile_finish()
|
||||||
|
{
|
||||||
|
local rc="${1:-0}"
|
||||||
|
if _profile_is_sourced; then
|
||||||
|
return "$rc"
|
||||||
|
fi
|
||||||
|
exit "$rc"
|
||||||
|
}
|
||||||
|
|
||||||
|
_profile_install_in_file()
|
||||||
|
{
|
||||||
|
local rc_file="$1"
|
||||||
|
local source_line="$2"
|
||||||
|
|
||||||
|
[[ -f "$rc_file" ]] || touch "$rc_file" || {
|
||||||
|
printf "[ Error ] Cannot create %s\n" "$rc_file" >&2
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
if grep -Fqx "$source_line" "$rc_file"; then
|
||||||
|
printf "[ Info ] Already configured in %s\n" "$rc_file"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
printf "\n%s\n" "$source_line" >> "$rc_file" || {
|
||||||
|
printf "[ Error ] Cannot write to %s\n" "$rc_file" >&2
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
printf "[ Info ] Added profile source line to %s\n" "$rc_file"
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
_profile_install()
|
||||||
|
{
|
||||||
|
local install_bashrc=0
|
||||||
|
local install_profile=0
|
||||||
|
local target_selected=0
|
||||||
|
local script_dir source_line rc=0
|
||||||
|
|
||||||
|
while [[ $# -gt 0 ]]; do
|
||||||
|
case "$1" in
|
||||||
|
--bashrc)
|
||||||
|
install_bashrc=1
|
||||||
|
target_selected=1
|
||||||
|
;;
|
||||||
|
--profile)
|
||||||
|
install_profile=1
|
||||||
|
target_selected=1
|
||||||
|
;;
|
||||||
|
-h|--help)
|
||||||
|
printf "Usage: %s --install [--bashrc] [--profile]\n" "${BASH_SOURCE[0]}"
|
||||||
|
printf "If no target is specified, both ~/.bashrc and ~/.profile are configured.\n"
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
printf "[ Error ] Unknown install option: %s\n" "$1" >&2
|
||||||
|
return 2
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
|
||||||
|
if (( target_selected == 0 )); then
|
||||||
|
install_bashrc=1
|
||||||
|
install_profile=1
|
||||||
|
fi
|
||||||
|
|
||||||
|
script_dir=$(dirname "$(realpath -s "${BASH_SOURCE[0]}")")
|
||||||
|
source_line="source \"$script_dir/profile.sh\""
|
||||||
|
|
||||||
|
if (( install_bashrc == 1 )); then
|
||||||
|
_profile_install_in_file "$HOME/.bashrc" "$source_line" || rc=$?
|
||||||
|
fi
|
||||||
|
|
||||||
|
if (( install_profile == 1 )); then
|
||||||
|
_profile_install_in_file "$HOME/.profile" "$source_line" || rc=$?
|
||||||
|
fi
|
||||||
|
|
||||||
|
return "$rc"
|
||||||
|
}
|
||||||
|
|
||||||
|
if [[ $# -gt 0 ]]; then
|
||||||
|
case "$1" in
|
||||||
|
--install)
|
||||||
|
shift
|
||||||
|
_profile_install "$@"
|
||||||
|
_profile_finish $?
|
||||||
|
;;
|
||||||
|
-h|--help)
|
||||||
|
printf "Usage: source %s\n" "${BASH_SOURCE[0]}"
|
||||||
|
printf " %s --install [--bashrc] [--profile]\n" "${BASH_SOURCE[0]}"
|
||||||
|
_profile_finish 0
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
printf "[ Error ] Unknown option: %s\n" "$1" >&2
|
||||||
|
_profile_finish 2
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! _profile_is_sourced; then
|
||||||
|
printf "[ Warning ] profile.sh is designed to be sourced, not executed directly.\n" >&2
|
||||||
|
printf "Use: source \"%s\"\n" "$(realpath -s "${BASH_SOURCE[0]}")" >&2
|
||||||
|
printf "Or run: %s --install [--bashrc] [--profile]\n" "${BASH_SOURCE[0]}" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ ! $SHELL =~ bash ]]; then
|
if [[ ! $SHELL =~ bash ]]; then
|
||||||
echo "That environment script is designed to be used with bash being the shell."
|
echo "That environment script is designed to be used with bash being the shell."
|
||||||
echo "Please consider using bash to enjoy our features!"
|
echo "Please consider using bash to enjoy our features!"
|
||||||
return 1
|
_profile_finish 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Required for associative arrays (4.0+) and namerefs (4.3+)
|
# Required for associative arrays (4.0+) and namerefs (4.3+)
|
||||||
@@ -48,6 +161,8 @@ if ((BASH_VERSINFO[0] < 4)) || [[ ${BASH_VERSINFO[0]} -eq 4 && ${BASH_VERSINFO[1
|
|||||||
(return 0 2>/dev/null) && return 1 || exit 1
|
(return 0 2>/dev/null) && return 1 || exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
unset -f _profile_is_sourced _profile_finish _profile_install_in_file _profile_install
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# path* : private functions for PATH variable management
|
# path* : private functions for PATH variable management
|
||||||
pathremove()
|
pathremove()
|
||||||
@@ -236,6 +351,10 @@ fi
|
|||||||
# Parse and load general configuration
|
# Parse and load general configuration
|
||||||
export PROFILE_CONF="$MYPATH/profile.conf"
|
export PROFILE_CONF="$MYPATH/profile.conf"
|
||||||
parse_conf "$PROFILE_CONF"
|
parse_conf "$PROFILE_CONF"
|
||||||
|
# Overload with user configuration if it exists
|
||||||
|
if [[ -f "$HOME/.profile.conf" ]]; then
|
||||||
|
parse_conf "$HOME/.profile.conf"
|
||||||
|
fi
|
||||||
load_conf system # Load Bash system behavior configuration (history, pager, etc.)
|
load_conf system # Load Bash system behavior configuration (history, pager, etc.)
|
||||||
load_conf general # General purpose configuration (compilation flags, etc.)
|
load_conf general # General purpose configuration (compilation flags, etc.)
|
||||||
|
|
||||||
@@ -255,6 +374,14 @@ shopt -u nullglob
|
|||||||
[[ $- == *i* ]] && export INTERACTIVE=1
|
[[ $- == *i* ]] && export INTERACTIVE=1
|
||||||
|
|
||||||
if [[ $INTERACTIVE ]]; then
|
if [[ $INTERACTIVE ]]; then
|
||||||
|
# Load custom bash completions
|
||||||
|
shopt -s nullglob
|
||||||
|
for _compl in "$MYPATH/profile.d/bash-completion/"*.sh; do
|
||||||
|
[[ -f "$_compl" && -r "$_compl" ]] && . "$_compl"
|
||||||
|
done
|
||||||
|
unset _compl
|
||||||
|
shopt -u nullglob
|
||||||
|
|
||||||
# For compiling (as we often compile with LFS/0linux...)
|
# For compiling (as we often compile with LFS/0linux...)
|
||||||
#Aliases
|
#Aliases
|
||||||
load_alias aliases
|
load_alias aliases
|
||||||
|
|||||||
Reference in New Issue
Block a user