DaemonForums  

Go Back   DaemonForums > OpenBSD > OpenBSD General

OpenBSD General Other questions regarding OpenBSD which do not fit in any of the categories below.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 20th February 2020
toprank toprank is offline
Fdisk Soldier
 
Join Date: Feb 2018
Posts: 54
Default vi "set backup" option

I'm wondering if this is the expected behaviour or if it's a bug.

With the following in ~/.nexrc

Code:
set backup=N"/home/$user/.vi/backup/%~"
If I edit a file from outside its directory, for example:

Code:
vi dev/x.py
Upon exit with :wq it errors with:

Code:
Error: /home/$user/.vi/backup/dev/x.py~: No such file or directory.
Whereas if editing the file from within its directory (e.g., vi x.py), vi does save a backup at ~/.vi/backup/x.py~1

On a somewhat related note, I must use set backup=N"/home/$user/.vi/backup/%~" because set backup=N"~/.vi/backup/%~" also errors with:

Code:
Error: "~/.vi/backup/%~": No such file or directory.
Regardless of whether opening the file from within or outside its directory.
Reply With Quote
  #2   (View Single Post)  
Old 23rd February 2020
fvgit's Avatar
fvgit fvgit is offline
Spikes in tights
 
Join Date: May 2016
Location: perl -MMIME::Base64 -le 'print decode_base64("U2hlcndvb2QgRm9yZXN0")'
Posts: 219
Default

While I don't have an answer to your question, I can certainly replicate both behaviours you're seeing. Though on my system $USER needs to be upper-case. Tested on 6.6 amd64 with my own ~/.exrc

If I set the backup uption to
Code:
set backup=N"%~"
it works from anywhere in the file system. But the backup files are always written into the same directory as the original file, accumulating over time with every :wq
Reply With Quote
  #3   (View Single Post)  
Old 24th February 2020
J65nko J65nko is offline
Administrator
 
Join Date: May 2008
Location: Budel - the Netherlands
Posts: 3,588
Default

On FreeBSD 12 with:
Code:
set backup=N"/home/$USER/.vi/backup/%.bak~
I can edit a file in the current directory and the backup is made .e.g. :
$ cd Iowa_caucus ; vi dhondt.sh
Code:
[adriaan@ProliantX /usr/home/adriaan/.vi/backup]$ ls -ltr
total 20
-rw-------  1 adriaan  adriaan    12 Feb 24 00:53 aap.bak1
-rw-------  1 adriaan  adriaan    29 Feb 24 00:55 aap.bak2
-rw-------  1 adriaan  adriaan   110 Feb 24 01:06 aap.bak~1
-rw-------  1 adriaan  adriaan  1298 Feb 24 01:09 dhondt.sh.bak~1
-rw-------  1 adriaan  adriaan  1326 Feb 24 01:10 dhondt.sh.bak~2
When I am in my home directory and edit the file with $ vi Iowa_caucus/dhondt.sh I get the following error:
Code:
+=+=+=+=+=+=+=+
Error: /home/adriaan/.vi/backup/Iowa_caucus/dhondt.sh.bak~: No such file or
directory.
Press any key to continue [: to enter more ex commands]:
So this phenomenon is not limited to OpenBSD
__________________
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump
Reply With Quote
  #4   (View Single Post)  
Old 24th February 2020
IdOp's Avatar
IdOp IdOp is offline
Too dumb for a smartphone
 
Join Date: May 2008
Location: twisting on the daemon's fork(2)
Posts: 896
Default

What happens if you create a sub-directory of the backup directory with the same name as the sub-directory the file is in? In toprank's example this would be

/home/$user/.vi/backup/dev

and in J65nko's example it would be

/home/$USER/.vi/backup/Iowa_caucus

I am guessing that vi is unwilling to create this itself.
Reply With Quote
  #5   (View Single Post)  
Old 24th February 2020
toprank toprank is offline
Fdisk Soldier
 
Join Date: Feb 2018
Posts: 54
Default

If I create the subdirectories in ~/.vi/backup, it works; however, I don't feel like recreating the system's directory tree in ~/.vi/backup. And creating the subdirectory prior to editing a file negates the utility of the set backup feature as I may as well just mkdir -p .vi/backup/file/path; cp file/path/file.name ~/.vi/backup/file/path/; vi file/path/file.name myself.

If the developers are aware that this is how it functions or purposely made it this way, that's cool; I wasn't sure if that's the case or if it's a bug, and would file a bug report if the latter.
Reply With Quote
  #6   (View Single Post)  
Old 24th February 2020
TronDD TronDD is offline
Package Pilot
 
Join Date: Sep 2014
Posts: 214
Default

Vi substitutes "%" with whatever was passed on the commandline. So if you edit ../somefile, it'll put the backup in ~/.vi/

Not ideal...
Reply With Quote
  #7   (View Single Post)  
Old 24th February 2020
IdOp's Avatar
IdOp IdOp is offline
Too dumb for a smartphone
 
Join Date: May 2008
Location: twisting on the daemon's fork(2)
Posts: 896
Default

I don't know why vi does it the way it does ... but FWIW here's my thinking about it.

If all backup files were put in the same directory (say, the top level ~/.vi/backup directory) then there could be collisions between the backups of files with the same name that originate in different directories, e.g.,

dir1/file and dir2/file

In an attempt to mitigate this problem, vi could create the necessary sub-directories. However, a little thought shows this will not solve all possible collision problems. So maybe they want the user to create these directories so they can be aware of and manage the potential issues?

That's all just a guessing on my part, and I haven't thought it through further than that. Quite possible there's another or better reason for how it works.
Reply With Quote
  #8   (View Single Post)  
Old 24th February 2020
TronDD TronDD is offline
Package Pilot
 
Join Date: Sep 2014
Posts: 214
Default

Also, if it didn't use the full path, in the typical use case where you want the backup saved in the same directory as the original file, editing ../somefile or docs/otherfile has to conider the path part or the backup will end up in the user's current directory, and not in the directory with the file.

It should probaby do something different if you specify an absolute path as the backup directory.
Reply With Quote
  #9   (View Single Post)  
Old 24th February 2020
J65nko J65nko is offline
Administrator
 
Join Date: May 2008
Location: Budel - the Netherlands
Posts: 3,588
Default

Quote:
Originally Posted by IdOp View Post
What happens if you create a sub-directory of the backup directory with the same name as the sub-directory the file is in?
[snip]
and in J65nko's example it would be

/home/$USER/.vi/backup/Iowa_caucus

I am guessing that vi is unwilling to create this itself.
Yes, that is the reason:
Code:
$  vi Iowa_caucus/dhondt.sh
Iowa_caucus/dhondt.sh: 82 lines, 1299 characters.
$ ls -ltrR .vi
total 4
drwxr-xr-x  3 adriaan  adriaan  512 Feb 24 19:19 backup

.vi/backup:
total 24
-rw-------  1 adriaan  adriaan    12 Feb 24 00:53 aap.bak1
-rw-------  1 adriaan  adriaan    29 Feb 24 00:55 aap.bak2
-rw-------  1 adriaan  adriaan   110 Feb 24 01:06 aap.bak~1
-rw-------  1 adriaan  adriaan  1298 Feb 24 01:09 dhondt.sh.bak~1
-rw-------  1 adriaan  adriaan  1326 Feb 24 01:10 dhondt.sh.bak~2
drwxr-xr-x  2 adriaan  adriaan   512 Feb 24 19:20 Iowa_caucus

.vi/backup/Iowa_caucus:
total 4
-rw-------  1 adriaan  adriaan  1331 Feb 24 19:20 dhondt.sh.bak1
Please note that this is with set backup=N"/home/$USER/.vi/backup/%.bak" because I thought the '~' could play a role or be the culprit.....
__________________
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump
Reply With Quote
Old 24th February 2020
bsdun's Avatar
bsdun bsdun is offline
Real Name: Steve
New User
 
Join Date: Feb 2020
Posts: 6
Default

I made a small shell script that will do backups for vi.
If you use this script you must disable backups in .nexrc and/or .exrc.
The script is here:
https://gitlab.com/bsdun/vibak.sh
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
option "POWER" does not load philo_neo71 FreeBSD General 0 22nd December 2017 06:59 PM
Difference between"arp info overwritten" and " duplicate IP address " varag OpenBSD Security 1 6th April 2015 02:57 PM
How to replace "ectags" with "ctags"? fender0107401 OpenBSD Packages and Ports 5 16th April 2013 10:01 AM
Fixed "xinit" after _7 _8, "how" here in case anyones' "X" breaks... using "nvidia" jb_daefo Guides 0 5th October 2009 09:31 PM
"Thanks" and "Edit Tags". diw Feedback and Suggestions 2 29th March 2009 12:06 AM


All times are GMT. The time now is 11:23 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick