Giter Site home page Giter Site logo

shell-history's Introduction

shell-history

Get the command history of the user's shell

Install

$ npm install shell-history

Usage

import {shellHistory, shellHistoryPath} from 'shell-history';

console.log(shellHistory());
//=> ['ava', 'echo unicorn', 'node', 'npm test', …]

console.log(shellHistoryPath());
//=> '/Users/sindresorhus/.history'

API

shellHistory()

Get an array of commands.

On Windows, unless the HISTFILE environment variable is set, this will only return commands from the current session.

shellHistoryPath()

Get the path of the file containing the shell history.

On Windows, this will return either the HISTFILE environment variable or undefined.

parseShellHistory(string)

Parse a shell history string into an array of commands.

Related

  • shell-path - Get the $PATH from the shell
  • shell-env - Get environment variables from the shell

shell-history's People

Contributors

kelion avatar richienb avatar rocktimsaikia avatar sindresorhus avatar thebrenny avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

shell-history's Issues

Why not shellHistory.path?

In the readme I see

console.log(shellHistory().path);

Does that not first enumerate the entire history (shellHistory(), a potentially lengthy operation) and then get the .path property from the result?

Why not compute the path to the history first and story it on the module.exports itself, allowing one to do

console.log(shellHistory.path);

.zsh_history file not found

Here's the error:

str.trim.split.map.Array.from.map.fp.reduce.module.exports.opts (node_modules/shell-history/index.js:60:18)
    module.exports (index.js:6:15)

This code caused it:

'use strict';

const shellHistory = require('shell-history');

module.exports = function (replaceMe) {
  console.log(shellHistory());
  return replaceMe;
};

Isolating the issue to just the getPath function:

node
> const h = require('shell-history')
undefined
> h.path()
undefined

I have an expected and non-empty .zsh_history location:

> os.homedir()
'/Users/dawsonbotsford'
 ~  cat /Users/dawsonbotsford/.zsh_history
: 1483040067:0;ls
: 1483040067:0;rm -rf .zsh
: 1483040067:0;ls
: 1483040067:0;rm .zsh*
...

sist output:

node

npm -v: 2.15.11
node --version: v4.7.0

shell

uname: Darwin
echo $SHELL: /bin/zsh
echo $TERM: xterm-256color
echo $TERM_PROGRAM: iTerm.app

Time created: Sun Jan 15 2017 18:15:54 GMT-0800 (PST)

Support Fish shell

Should add this path path.join(homeDir, '.config/fish/fish_history') to the paths array, but not sure of the format of the history file. Any Fish users wanna help out?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.