diff options
Diffstat (limited to '.config/fish')
| -rw-r--r-- | .config/fish/functions/install_scripts.fish | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/.config/fish/functions/install_scripts.fish b/.config/fish/functions/install_scripts.fish new file mode 100644 index 0000000..541b5bd --- /dev/null +++ b/.config/fish/functions/install_scripts.fish | |||
| @@ -0,0 +1,31 @@ | |||
| 1 | #!/usr/bin/env fish | ||
| 2 | |||
| 3 | function prepare_directories | ||
| 4 | if not test -d "$LOCAL_BIN" | ||
| 5 | mkdir "$LOCAL_BIN" | ||
| 6 | end | ||
| 7 | |||
| 8 | if not test -d "$LOCAL_SCRIPTS" | ||
| 9 | echo "$LOCAL_SCRIPTS not found" | ||
| 10 | return 1 | ||
| 11 | end | ||
| 12 | end | ||
| 13 | |||
| 14 | function install_scripts | ||
| 15 | prepare_directories | ||
| 16 | |||
| 17 | for script in "$LOCAL_SCRIPTS"/* | ||
| 18 | if string match -q "#!*" (head -n1 "$script") | ||
| 19 | string match -rq '^(?<filename>.*)(?<ext>\.[^.]*)$' (basename "$script") | ||
| 20 | set symlink "$LOCAL_BIN/$filename" | ||
| 21 | |||
| 22 | if test -L "$symlink" | ||
| 23 | echo "$filename" already exists | ||
| 24 | continue | ||
| 25 | end | ||
| 26 | |||
| 27 | ln -s "$script" "$symlink" | ||
| 28 | echo "$filename symlinked" | ||
| 29 | end | ||
| 30 | end | ||
| 31 | end | ||
