diff options
| Commit | fbc352119e3e4fa37546ac8ad62989c87162888e (patch) | |
|---|---|---|
| Author | 2026-11-08 14:34:12 +0200 | |
| Committer | 2026-11-08 14:34:12 +0200 | |
| Files | 4bcd56b41183196b5895065ddf1c3a79632d9dd8 /make | |
| .files-fbc352119e3e4fa37546ac8ad62989c87162888e.tar .files-fbc352119e3e4fa37546ac8ad62989c87162888e.tar.gz .files-fbc352119e3e4fa37546ac8ad62989c87162888e.zip | ||
| Parent | 4d0540a644131bc00709a426a11919f0b3810d89 (diff) | |
feat(make): Add export functionality
1 files changed, 62 insertions, 0 deletions
| -rwxr-xr-x | make | 62 |
@@ -211,8 +211,70 @@ import() { done } +export_() { + shift + + for arg in "$@" + do + [ -z "$arg" ] && continue + + file="$(realpath "$arg")" + if [ "${file#$PWD}" = "$file" ] + then + echo "'$file' is not under '$PWD'! Can only export from .files directory!" >/dev/stderr + continue + fi + + if [ -f "$file" ] + then + home_file="${file#$PWD}" # Remove .files path + home_file="${home_file#/}" # Remove leading /, if it exists + home_file="${home_file#*/}" # Remove directory under .files + + home_dir="$(realpath "$HOME/${home_file%/*}")" + + if [ "${home_dir#$PWD}" != "$home_dir" ] + then + echo "'$home_dir is under '$PWD'! Refusing to export dir to .dirs!" >/dev/stderr + continue + fi + mkdir -p "$home_dir" + + home_file="$HOME/$home_file" + if [ -h "$home_file" ] + then + rm "$home_file" + fi + + # Output file exists and has different content -> swap the two files + # With git it's easy to find the differences and accept/discard them + # This makes things more annoying since to accept changes (after export), + # you'll need to export again (swap back), import and then export. + # Declining changes requires a git discard, which is more ok. + if [ -f "$home_file" ] && ! cmp -s "$file" "$home_file" + then + echo "Warn: '$home_file' is different from '$file'! Swapping the contents of the files!" >/dev/stderr + mv "$home_file" "__.files_tmp.$$" + mv "$file" "$home_file" + mv "__.files_tmp.$$" "$file" + else + cp "$file" "$home_file" + fi + + echo "Exported '$file' to '$home_file'" + elif [ -d "$file" ] + then + # TODO: Recursively traverse output directories and copy when you can + echo "Directories not currently supported!" >/dev/stderr + else + echo "'$file' must be either a normal file or directory!" >/dev/stderr + fi + done +} + case "$1" in (import) import "$@" ;; + (export) export_ "$@" ;; (unlink) unlink ;; (link|*) link ;; esac |
