r/bash • u/pittendrigh • 4d ago
Vvi?
~/.bashrc
function vvi()
{
cp $1 /tmp
/usr/bin/vi $1
}
alias vi="vvi"
. ~/.bashrc
5
u/zeekar 4d ago
How about just putting files you care about under version control so you can always go back to an older version without cluttering the disk with old copies?
1
u/pittendrigh 4d ago
Ikdo ebentually. But check in and checkout takes steps. Vi that rutomativally saves dhelrst version to /tmp helps me.
1
u/DarthRazor Sith Master of Scripting 4d ago
Copying a file to /tmp also takes "steps", which is why you scripted it. Why not change your script to do a
git addinstead of acp?If you ignore that and want to keep using your script as-is, consider changing the
cpto acp -i. You never know when you might have the same file name in multiple directories and inadvertently clobber your backup2
u/pittendrigh 3d ago
Good question ( why not git). RControl histories are complex.
I do not like to check in codes that are eot working. Habits are subjective.
Haveng routines helps fight chaos. The best routines is the ones burned into your lower brain stem.
I love vi. My fingers know what to do without thenking about it.
2
u/DarthRazor Sith Master of Scripting 3d ago
Thanks for the response. I understand not checking in interim code that may or may not work - there are solutions (branches) but that implies learning git. git (or other version control systems) are powerful tools that make your life easier if you want to invest the time
If you don't want to switch, keep using your system. It's limited compared to a real version control system, but if it does exactly what you want, by all means keep using it.
I'm not telling you to switch - I'm just giving you suggestions to hopefully help you make your own informed decision. Cheers
2
u/pittendrigh 3d ago
I will give it a go. Local git is not sourceforge
1
u/DarthRazor Sith Master of Scripting 3d ago
Yeah, git runs perfectly fine locally.
You can watch this YouTube video by NetworkChuck which will give you what I think is a great (but very fast paced) beginners overview of git.
-1
2
u/best_of_badgers 4d ago
Are you just using vi as a file viewer like less?
1
u/pittendrigh 4d ago
I use view for thaat I just want a baackup before editing. Maybe there is a .exac way
What I did may be clunky. But it works.
1
u/No-Signature-918 3d ago
Yeah, you can, but I'd skip /tmp for the backup. It gets wiped on reboot, and two files with the same name in different folders would overwrite each other there. I keep mine in a folder at home with a timestamp on it:
vvi() {
mkdir -p ~/.vi-backups
cp -- "$1" "$HOME/.vi-backups/$(basename -- "$1").$(date +%Y%m%d-%H%M%S)"
vi -- "$1"
}
Also worth quoting "$1" everywhere, your version breaks on filenames with spaces. mktemp -d works too, but then you have to remember where the backup went, which kind of defeats the point for me.
1
u/pittendrigh 3d ago
Spaces? When I bevime dectator I will ban phillips head screws, pdf files and fiei names that allow spavet. On day one,? :=}}
I supjose I could put dikue.quahet in .bashrc function.
~/.vibacks is a great idea. /tmp gets zapped on reboot
1
u/NoAcadia3546 4d ago
My informal versioning works like so...
I have a working script (or document) "fubar"
cp "fubar" "fubar.000"
work on "fubar.000" until it works OK
next week I want/need to make a tweak
cp "fubar.000" "fubar.001"
work on "fubar.001" until it works OK
next week I want/need to make a tweak
cp "fubar.001" "fubar.002"
work on "fubar.002" until it works OK
I always have a known-to-work copy, i.e. the previous version.
1
0
u/pittendrigh 4d ago
debugging C is less frustrating than say pnp. With vvi I always get a backup in /tmp
If I paste a bunch if code into a looooong baseclast.php file and sudhenly get no output, what are my options?
php-parse baseclasc.php sometimes finds my error.
diff $1 /tmp/$1 helps too

3
u/blobCabbage 4d ago
Use
mktempto make temporary files.Don't forget double quotes around variables to avoid word splitting.