Skip to content

Instantly share code, notes, and snippets.

@chapmanjacobd
Last active September 5, 2022 20:09
Show Gist options
  • Save chapmanjacobd/c7c3af1d2d39ca55346349fffa2e5fd5 to your computer and use it in GitHub Desktop.
Save chapmanjacobd/c7c3af1d2d39ca55346349fffa2e5fd5 to your computer and use it in GitHub Desktop.
move lines of text
# 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
@chapmanjacobd
Copy link
Author

I use this a few times a week along with:

function mvlj
    for dfolder in $argv
        mvl ~/.jobs/todo/$dfolder ~/.jobs/done/$dfolder
    end
end

and

function mvljs --argument s
    for folder in ~/.jobs/todo/*
        set dfolder (basename "$folder")
        mvl -s"$s" ~/.jobs/todo/$dfolder ~/.jobs/done/$dfolder
    end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment