Last active
September 5, 2022 20:09
-
-
Save chapmanjacobd/c7c3af1d2d39ca55346349fffa2e5fd5 to your computer and use it in GitHub Desktop.
move lines of text
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# requires moreutils | |
function mvl --description 'move lines' | |
argparse --min-args 2 'h/help' 's/search=' -- $argv | |
or return 1 | |
set src $argv[1] | |
set dest $argv[2] | |
if set -q _flag_help | |
echo "Move lines of text from one file to another" | |
echo "example: mvl -s'buy milk' todo.txt done.txt" | |
return 0 | |
end | |
if set -q _flag_search | |
grep -i "$_flag_search" "$src" | tee -a "$dest" | |
grep -iv "$_flag_search" "$src" | sponge "$src" | |
else | |
if confirm "move all lines from $src to $dest (y/N) " | |
cat "$src" | tee -a "$dest" | |
truncate -s 0 "$src" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I use this a few times a week along with:
and