lackadaisical/sw
Sam Hardeman 160a7763b7 - Minor cleanup
- Change shebangs to use 'env' in prep for NixOS (and others)
- `agenda` now has a symlink to the underlying tree structure named ".tree"
- `binbox` has more checking, being prepped for automatic export of symlinks.
- `cdz` now symlinks to the archive directory using "<archive name>.tmp". This is less confusing than a randomized extraction folder, and adds the benefit of being in the FS-tree of the original archive.
- daisy.source changes:
> Added basic debug mode.
> `ched` can now set global (all of the shell) editor or local (lackadaisical utils only) editor.
> The encoding/decoding functions have been expanded and improved. Extra checking, permissions are stored as well, `daisy_dec` can handle stdin.
- Added new functions to manage lackadaisical config: daisy_backup (runs `bak` on config files), daisy_clear (removes config files), and daisy_restore (restores config files archived using bak).
- All functions/tools prefixed with 'daisy_' are now also available prefixed with 'ld_' instead
- Added a new utility, `clip`. This utility keeps a local variable that can be set if given args and get if no args are supplied. Basically a simple clipboard local to the ptty. Supports stdin.
2026-01-25 18:23:05 +01:00

49 lines
942 B
Bash
Executable file

#!/usr/bin/env bash
# It just swaps two files
LD_INTERNAL1
. $(dirname $(realpath $0))/daisy.source
file1=$1
file2=$2
function helpFn()
{
error=$?
if [[ $error -gt 0 ]];
then
error_text=$(perl -E 'say $!=shift' $error)
echo "$LD_BIN error ($error): $error_text"
fi
echo "Usage: $LD_BIN <file1> <file2>"
echo Swap two files in a filesystem.
exit $error
}
if [[ $@ == *"--help"* ]];
then
helpFn
elif [[ $@ == '' ]];
then
echo "No arguments specified."
helpFn
fi
# We set a trap here, together with 'set -e' above,
# this makes sure we exit gracefully if we have an
# error in one of the ls or mv calls.
trap helpFn ERR
# We want to swap two files
# Easy, but let's be safe about it
ls "$file1" >/dev/null
ls "$file2" >/dev/null
# Files should exist, now we move
mv "$file1" "$file1.sw"
mv "$file2" "$file2.sw"
# We got our moved copies, now we simply rename
mv "$file1.sw" "$file2"
mv "$file2.sw" "$file1"