-
-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve Windows compatibility #5
Conversation
I don't really understand the point. It gets only the session history, but not permanent history? However, the session history is nothing as we're spawning the terminal. Can you please elaborate? |
I know it doesn't get a persistent history, but getting the session's history is also a common use case (I imagine). Otherwise, if a HISTFILE env variable is set, that file should be used - because there are tools out there which persist CMD history across sessions. Otherwise, a session history use case would be: $ git clone https://github.com/sindresorhus/shell-history.git && alert Where I hope that makes more sense. |
But does it actually get the history of the whole session? Like commands executed before |
Please always run |
The special Windows behavior (of only getting the session history) needs to be documented. |
I tried running the tests but it just isn't working. First, there are issues because I then decided to skip the whole Calling At the end of the day, I converted test.js to Node's I didn't plan on giving you my life story on trying to run XO and Ava, so sorry about that! 😅
Doneskies. Send feedback! 🎉 |
XO works fine on all those setups. This is a problem with your setup. But you can look at the lint failures in the Travis output and fix manually. |
#5 (comment) is not resolved. Please read my comment again. I think it's quite clear. |
Sorry I missed this comment -- I've added #6 Fixed my problems (big ty @rocktimsaikia 🎉) -- Test now passes correctly.
You are correct it wasn't resolved - I didn't realise that This has now been resolved. |
readme.md
Outdated
|
||
### shellHistory.path() | ||
|
||
Get the path of the file containing the shell history. | ||
|
||
On Windows, this will return either the `HISTFILE` environment variable, or null. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see any null
in the code.
index.js
Outdated
@@ -63,7 +60,17 @@ module.exports = options => { | |||
options = options || {}; | |||
|
|||
if (process.platform === 'win32') { | |||
return []; | |||
const histFile = getPath(options); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The naming is an implementation detail of the getPath
method.
const histFile = getPath(options); | |
const historyPath = getPath(options); |
index.js
Outdated
|
||
// No histfile used -- spawn a doskey | ||
const childProcess = require('child_process'); | ||
const doskey = childProcess.spawnSync('doskey', ['/history'], { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const doskey = childProcess.spawnSync('doskey', ['/history'], { | |
const {stdout} = childProcess.spawnSync('doskey', ['/history'], { |
index.js
Outdated
const doskey = childProcess.spawnSync('doskey', ['/history'], { | ||
encoding: 'utf8' | ||
}); | ||
return doskey.stdout.trim().split('\r\n') || []; // Enforce array |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment is moot. The code is clear enough.
index.js
Outdated
} | ||
|
||
// No histfile used -- spawn a doskey | ||
const childProcess = require('child_process'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Imports should be at the top of the file.
test_win.bat
Outdated
@echo off | ||
|
||
echo Print entire history | ||
node -p "const history = require('./'); history()" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
node -p "const history = require('./'); history()" | |
node -p "const history = require('.'); history()" |
test_win.bat
Outdated
pause | ||
echo. | ||
echo Print last command (which will be "test_win.bat") | ||
node -p "const history = require('./'); let h = history(); h[h.length-1]" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
node -p "const history = require('./'); let h = history(); h[h.length-1]" | |
node -p "const history = require('.'); let h = history(); h[h.length - 1]" |
test_win.bat
Outdated
@@ -0,0 +1,12 @@ | |||
:: Acts as a windows tester. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sentence is not clear enough and it's Windows
.
index.js
Outdated
return ''; | ||
} | ||
|
||
// HISTFILE might be cross-platform, so win32 check is after! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"might" is not a good explanation. Explain exactly when it would be.
Then that should be explained. |
No technical benefit in this case. But it's more readable to declare it upfront. It does matter when it comes to streams though, as it might end up splitting Unicode characters incorrectly. |
Please spend some more time perfecting this pull request. |
Bump |
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
Added a method to acquire the session history on windows. It doesn't get the history, and also doesn't check to see if the user has a HISTFILE environment variable. But I don't know if any windows user actually has one for CMD.
This won't work if invoked through PowerShell though, because PS uses the history command.
🙏