Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add aconfmgr cd command #165

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Since the system configuration is described as shell scripts, it is trivially ex

* [Usage](#usage)
* [Installation](#installation)
* [Add cd command](#add-cd-command)
* [First run](#first-run)
* [Maintenance](#maintenance)
* [Restoring](#restoring)
Expand Down Expand Up @@ -45,6 +46,21 @@ Since the system configuration is described as shell scripts, it is trivially ex

Simply clone (or [download](https://github.com/CyberShadow/aconfmgr/archive/master.zip)+unzip) the GitHub repository. `aconfmgr` will install dependencies as needed during execution. [An AUR package is also available](https://aur.archlinux.org/packages/aconfmgr-git/).

#### Add cd command

To be able to change to the aconfmgr configuration directory quickly with the command `aconfmgr cd`. Add the following function to your shell startup file. (e.g., `/etc/profile.d/aconfmgr.sh`, `~/.bashrc`, `~/.zshrc`).

```sh
function aconfmgr() {
if [ "$1" = "cd" ]; then
shift
cd ~/.config/aconfmgr
else
command aconfmgr "$@"
fi
}
```

### First run

Run `aconfmgr save` to transcribe the system's configuration to the configuration directory. This will create the file `99-unsorted.sh` in the configuration directory, as well as other files describing the system configuration. (The configuration directory will usually be `~/.config/aconfmgr`, or `./config` if running directly from git, or it can be overridden with `-c`.)
Expand Down
17 changes: 16 additions & 1 deletion src/main.bash
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ function Usage() {
printf ' apply Update the system to reflect the current contents of the configuration\n'
printf ' check Syntax-check and lint the configuration\n'
printf ' diff Compare configuration and system\n'
printf ' cd Change current directory to the configuration directory\n'
echo
printf 'Supported options:\n'
printf ' -h, --help Print this message\n'
Expand Down Expand Up @@ -65,7 +66,7 @@ function Main() {
while [[ $# != 0 ]]
do
case "$1" in
save|apply|check|diff)
save|apply|check|diff|cd)
if [[ -n "$aconfmgr_action" ]]
then
UsageError "An action has already been specified"
Expand All @@ -78,6 +79,20 @@ function Main() {
then
aconfmgr_action_args=("$@")
break
elif [[ "$aconfmgr_action" == cd ]]
then
echo "To add the 'aconfmgr cd' function to your shell, add the following lines to your shell's startup file (e.g., ~/.bashrc, ~/.zshrc):"
echo ""
echo "function aconfmgr() {"
echo " if [ \"\$1\" = \"cd\" ]; then"
echo " shift"
echo " cd ~/.config/aconfmgr"
echo " else"
echo " command aconfmgr \"\$@\""
echo " fi"
echo "}"
echo ""
Exit 0
fi
;;
-h|--help|help)
Expand Down