Repository: saulpw/visidata

Issue:
[save_filetype] when save_filetype is set, you cannot gY as any other filetype on the DirSheet
**Small description**
I use `options.save_filetype = 'jsonl'` in my `.visidatarc`. I use this to set my default save type. However, sometimes I like to copy rows out as different file types, csv, fixed etc. and so I press gY and provide [e.g.] `copy 19 rows as filetype: fixed` but the response I get back is `"fixed" │ copying 19 rows to system clipboard as fixed │ saving 1 sheets to .fixed as jsonl` and the rows that are copied are in fact `jsonl`.

**Expected result**
To be able to set `options.save_filetype` and this be provided as the default option when copying and/or saving, however be able to save as different filetypes on-the-fly (as expected).

**Actual result with screenshot**
Shown above

**Steps to reproduce with sample data and a .vd**

1. Set `options.save_filetype = 'jsonl'` in `.visidatarc`
2. open a ~~file~~ directory (DirSheet) _< edited 2023-03-01_
3. Select some rows
4. Press `gY` (`syscopy-selected`)
5. enter "fixed"



Discussion:
Oh, this is fun.
Unfortunately, I cannot reproduce this on `develop` @geekscrapy!

![Peek 2023-02-27 17-56](https://user-images.githubusercontent.com/7489659/221733076-b25fd0b8-7c85-4492-9c09-0656a050a98b.gif)

I also cannot reproduce when I pass `fixed`!

I just copied this:

```
OrderDate    Region    Rep        Item      Units   Unit_Cost   Total     
2016-01-06   East      Jones      Pencil    95      1.99        189.05    
2016-01-23   Central   Kivell     Binder    50      19.99       999.50    
2016-02-09   Central   Jardine    Pencil    36      4.99        179.64    
```
@geekscrapy which version of VisiData are you on? At some point, `save_filetype` overrode the file extension. This was reverted in this commit: a4ea5cf65b7b03ead75cfadd1935d95d259b49b6. This should be the case since v2.9.


Hmm, I'm on 2.11, but just updated to dev (`pip install git+https://github.com/saulpw/visidata.git@develop`).... Aaand still there :)

Running with: `vd . --config=/dev/null`

This is _odd_. I think this is why I ignored it for so long :)
Another repo 🤷‍♂️ FWIW

1. `vd . --config=/dev/null --save_filetype=jsonl`
2. `gt`
3. `gY`
4. "fixed"

```
saving 1 sheets to .fixed as jsonl
copying 2 files to system clipboard as fixed
"fixed"
Do you think I can listen all day to such stuff?
opening . as dir
ImportError: cannot import name 'tempfile' from 'visidata.deprecated' (/Users/geekscrapy/python37/lib/python3.7/site-packages/visidata/deprecated.py)
saul.pw/VisiData v2.12dev
```
~~Ha, got it.... Nothing to do with `save_filetype`... `--config` and fixed with `--visidata_dir`!~~

~~Options were still being loaded even if I used `--config=/dev/null`. Once I set `--visidata_dir=/tmp` the issue went away~~

~~`vd . --visidata_dir=/tmp/ --config=/dev/null`~~

~~I noticed that plugins were still being loaded with `--config=/dev/null`, but the `.visidatarc` was not. Still unsure which of my plugins is setting `save_filetype` or doing something funky with saving though to make this an issue in the first place~~

I need moar coffee, it still fails with `visidata_dir` being set. I have to leave this for today (work to do :)) but if you have something I can try, I'll give it a go tomorrow
Aha! Yeah, this is happening on the *DirSheet*, that was the info I neded to reproduce! I noticed your strange "saving to .fixed", and thought you had sanitised the name out for privacy concerns. 
Haha! 

The problem is:

```
def saveSheets
[...]
filetype = givenpath.ext or options.save_filetype
```

And then the *DirSheet*'s funky path names (`.fixed`) do not have a clear extension. So it falls back to `options.save_filetype`.

Resolving patch:
diff --git a/visidata/path.py b/visidata/path.py
--- a/visidata/path.py
+++ b/visidata/path.py
@@ -153,6 +153,8 @@ def given(self, given):
         self.ext = self.suffix[1:]
         if self.suffix:  #1450  don't make this a oneliner; [:-0] doesn't work
             self.name = self._path.name[:-len(self.suffix)]
+        elif self._given == '.':  #1768
+            self.name = '.'
         else:
             self.name = self._path.name
 


Test patch: