Skip to content

Commit

Permalink
fix(config)!: ONE_LINKS_CONF receive two parameters: os, arch
Browse files Browse the repository at this point in the history
BREAKING CHANGE:

The value of OS changed from "MacOS" to "Darwin"
  • Loading branch information
adoyle-h committed Feb 14, 2023
1 parent ac6f105 commit d40deb0
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 28 deletions.
29 changes: 16 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,27 +116,30 @@ And `one config <key>` to query config option.

### ONE_LINKS_CONF

`ONE_LINKS_CONF` is a bash function that returns a filepath of [dotbot][] config.
`ONE_LINKS_CONF` is a bash function that returns a filepath of [dotbot][] config. Defaults to empty.

This function receives a parameter that is current OS. So you can manage different ONE_LINKS_CONF for different OS (such as MacOS, Linux).

[dotbot][] is used to manage symbol links of dotfiles (or any files).
You can use the [dotfiles from one.share][one.share] or from your own dotfiles.

The default `ONE_LINKS_CONF` return empty. User should defined yours in ONE_CONF file.
This function receives two parameters: OS (`uname -s`), Arch (`uname -m`).
It is used for managing different [dotbot][] configs for different environments (such as MacOS and Linux).

```sh
# User should print the path of ONE_LINKS_CONF file
# @param os type
# @param os $(uname -s)
# @param arch $(uname -m)
ONE_LINKS_CONF() {
case "$1" in
MacOS) echo "$DOTFILES_DIR"/links/macos.yaml ;;
Linux) echo "$DOTFILES_DIR"/links/debian.yaml ;;
local os=$1
local arch=$2
case "$os_$arch" in
Darwin_arm64) echo "$DOTFILES_DIR"/links/macos_arm.yaml ;;
Darwin_amd64) echo "$DOTFILES_DIR"/links/macos_intel.yaml ;;
Linux*) echo "$DOTFILES_DIR"/links/linux.yaml ;;
esac
}
```

You can copy the [one.links.example.yaml][] from [one.share][] to your directory.
The [dotbot][] is a tool to manage symbol links of dotfiles and any other files. It is a part of one.bash.
You can use it to create symbol links to any files.

There is a dotbot config template in [one.share][]. You can copy [one.links.example.yaml][] to your directory.

```sh
cp "$ONE_SHARE_DIR"/one.links.example.yaml "$DOTFILES_DIR"/one.links.yaml
Expand All @@ -147,7 +150,7 @@ $EDITOR "$DOTFILES_DIR"/one.links.yaml
Invoke `one link` to create symbol links based on ONE_LINKS_CONF file.
**Notice: Do not invoke `one link` with sudo.**

Invoke `one unlink` to remove all links defined in ONE_LINKS_CONF file.
Invoke `one unlink` to remove all symbol links based on ONE_LINKS_CONF file.

You can use [dotbot plugins](https://github.com/anishathalye/dotbot#plugins) for more directives.
See https://github.com/anishathalye/dotbot/wiki/Plugins
Expand Down
30 changes: 17 additions & 13 deletions README.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,26 +116,30 @@ EOF

### ONE_LINKS_CONF

`ONE_LINKS_CONF` 是一个 Bash 函数,它返回 [dotbot][] 配置的文件路径。
该函数接收一个参数,值为当前系统的标识。这样你可以管理不同系统下的不同 ONE_LINKS_CONF(比如 MacOS, Linux)
`ONE_LINKS_CONF` 是一个 Bash 函数,它返回 [dotbot][] 配置的文件路径。默认为空。

[dotbot][] 通过软链接管理配置文件(或者任何文件)。
你可以使用 [one.share 里的配置文件][one.share] 或者使用你自己的。

默认的 `ONE_LINKS_CONF` 为空。用户需要在 ONE_CONF 文件里定义你自己的文件路径。
该函数接收两个参数:OS (`uname -s`) 和 Arch (`uname -m`)。
它可以用来管理不同系统下的不同 [dotbot][] 配置(比如 MacOS 和 Linux)。

```sh
# User should print the path of ONE_LINKS_CONF file
# @param os type
# @param os $(uname -s)
# @param arch $(uname -m)
ONE_LINKS_CONF() {
case "$1" in
MacOS) echo "$DOTFILES_DIR"/links/macos.yaml ;;
Linux) echo "$DOTFILES_DIR"/links/debian.yaml ;;
local os=$1
local arch=$2
case "$os_$arch" in
Darwin_arm64) echo "$DOTFILES_DIR"/links/macos_arm.yaml ;;
Darwin_amd64) echo "$DOTFILES_DIR"/links/macos_intel.yaml ;;
Linux*) echo "$DOTFILES_DIR"/links/linux.yaml ;;
esac
}
```

你可以从 [one.share][] 拷贝 [one.links.example.yaml][] 到你的目录。
[dotbot][] 是一个通过软链接管理配置文件(或者任何文件)的工具。
你可以用它来创建软链接,指向任何文件。

[one.share][] 提供了一个 dotbot 配置模板。你可以拷贝 [one.links.example.yaml][] 到你的目录。

```sh
cp "$ONE_SHARE_DIR"/one.links.example.yaml "$DOTFILES_DIR"/one.links.yaml
Expand All @@ -144,9 +148,9 @@ $EDITOR "$DOTFILES_DIR"/one.links.yaml
```

调用 `one link` 会根据 ONE_LINKS_CONF 创建软链接。
**Notice: 不要用 sudo 调用 `one link`**
**注意: 不要用 sudo 调用 `one link`**

调用 `one unlink` 会根据 ONE_LINKS_CONF 移除目标软链接文件
调用 `one unlink` 会根据 ONE_LINKS_CONF 移除软链接文件

你可以使用 [dotbot 插件](https://github.com/anishathalye/dotbot#plugins) 来获得更多指令。
详见 https://github.com/anishathalye/dotbot/wiki/Plugins
Expand Down
2 changes: 1 addition & 1 deletion one-cmds/link
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ else
exit 6
fi

DOTBOT_CONF=$(ONE_LINKS_CONF "$(l.detect_os)")
DOTBOT_CONF=$(ONE_LINKS_CONF "$(uname -s)" "$(uname -m)")

if [[ ! -f $DOTBOT_CONF ]]; then
echo "Not found file '$DOTBOT_CONF'. Check the ONE_LINKS_CONF function in your config." >&2
Expand Down
2 changes: 1 addition & 1 deletion one-cmds/unlink
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ else
exit 6
fi

DOTBOT_CONF=$(ONE_LINKS_CONF "$(l.detect_os)")
DOTBOT_CONF=$(ONE_LINKS_CONF "$(uname -s)" "$(uname -m)")

if [[ ! -f $DOTBOT_CONF ]]; then
echo "Not found file '$DOTBOT_CONF. Check the ONE_LINKS_CONF function in your config." >&2
Expand Down

0 comments on commit d40deb0

Please sign in to comment.