Giter VIP home page Giter VIP logo

advanced-shell-history's Introduction

hilbert-6

advanced-shell-history's People

Contributors

barabo avatar sjjf 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

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

advanced-shell-history's Issues

Only the first line of a multi-line command is recorded.

Run a command like:

echo '1
2
3'

and ash will only record echo '1

This happens because read only reads the first line, see

read -r cmd_no start_ts cmd <<< "$( builtin history 1 )"
read -r no start end cmd <<< "$( __ash_last_command )"
read -r cmd_no cmd <<< "$( builtin history -1 )"

I've only tested this in bash, but if zsh's read works the same then it will have the same bug.

bash: __ash_precmd: command not found

I often use a command to open another terminal in the same directory as the current one:
alias fork='urxvt &'

However, if I use this command together with ash I get the error message bash: __ash_precmd: command not found; everytime I run a command.

ASH_SESSION_ID set but __ash_* functions not defined

I run ash on my Ubuntu desktop, with a large collection of gnome-terminal sessions running across multiple windows, all started from a single terminal. ash works nicely in the first session, but later sessions somehow inherit the ASH_SESSION_ID value in their environment but not the function definitions - simply checking for the session id and bailing doesn't result in a usable environment.

I have a fix for this issue, and I'll submit a pull request for it - I'm not sure if there's a better approach, though. Looking at the other open issue at the moment (#3) it's possible that this is something that happens more broadly than just my environment . . .

UTF-8 characters are dropped in the database

I have the given folder in my filesystem:

/home/io/projets/fanfare-ligugé

But in the ASH sqlite database, the accentuated character é of the folder name has been dropped everywhere.

I.e., the cwd value is:

/home/io/projets/fanfare-ligug

The following columns of the table commands have this kind of issue:

  • cwd
  • command

I have checked many entries in the table commands, and I can notice that all accentuated characters have been dropped.

Shell code appears before "Advanced Shell History enabled: session ..."

I use ZSH. I have put the following code in my zshrc:

source /usr/local/etc/advanced-shell-history/config
export ASH_CFG_SYSTEM_QUERY_FILE
source /usr/local/lib/advanced_shell_history/sh/zsh

When I start zsh, the following appears above my prompt.

__ash_end_session () {
        [[ "${ASH:-0}" == "0" ]] && __ash_info __ash_end_session && return
        __ash_log "${@}"
        ${ASH_LOG_BIN} --end_session --exit ${1}
}
__ash_log () {
        [[ "${ASH:-0}" == "0" ]] && __ash_info __ash_log && return
        if [[ "${ASH_SKIP:-1}" == "1" ]]
        then
                ASH_SKIP=0
                return
        fi
        local no start end cmd rval="${1}"  && shift
        read -r no start end cmd <<< "$( __ash_last_command )"
        local pipes="$( sed -e 's: :_:g' <<< "${@}" )"
        ${ASH_LOG_BIN} -e ${rval:-0} -s ${start:-0} -f ${end:-0} -n ${no:-0} -p "${pipes:-0}" -c "${cmd:-UNKNOWN}"
}
Advanced Shell History enabled: session 7

I had only expected the last line, not the two function definitions. I noticed the reporter of #8 had the same, but it seemed unrelated to their issue.

(Seemingly) relevant environment variables:

ASH_CFG=/usr/local/etc/advanced-shell-history/config
ASH_CFG_DB_FAIL_RANDOM_TIMEOUT=4
ASH_CFG_DB_FAIL_TIMEOUT=2
ASH_CFG_DB_MAX_RETRIES=30
ASH_CFG_DEFAULT_FORMAT=auto
ASH_CFG_HIDE_USAGE_FOR_NO_ARGS=false
ASH_CFG_HISTORY_DB=/home/maienm/.ash/history.db
ASH_CFG_LIB=/usr/local/lib/advanced_shell_history/sh
ASH_CFG_LOG_DATE_FMT='%Y-%m-%d %H:%M:%S %Z: '
ASH_CFG_LOG_FILE=/home/maienm/.ash/ash.log
ASH_CFG_LOG_IPV4=true
ASH_CFG_LOG_IPV6=true
ASH_CFG_LOG_LEVEL=WARNING
ASH_CFG_MOTD='Advanced Shell History enabled: '
ASH_CFG_SKIP_LOOPBACK=true
ASH_CFG_SYSTEM_QUERY_FILE=/usr/local/etc/advanced-shell-history/queries
ASH_LOG_BIN=/usr/local/bin/_ash_log
ASH_SESSION_ID=7
ASH_SKIP=0
HISTFILE=/home/maienm/.zhistory
HISTSIZE=10000
SAVEHIST=10000

zsh version: 5.6.2 (x86_64-pc-linux-gnu)
ash commit: 3a9b1fc2fcbe57496a70ec062cc0a4fdb1bb2ad5

no such file or directory: /usr/local/bin/_ash_log

Expected Behavior

I am using zsh with advanced-shell-history python version, after source /usr/local/lib/advanced_shell_history/sh/zsh, I should be able to use advanced-shell-history directly.

Current Behavior

zsh tells me in start up: no such file or directory: /usr/local/bin/_ash_log

Possible Solution

The problem is that the python version use _ash_log.py instead of _ash_log. We can fix it use a simple symbol link. It should be added to the make file.

ln -s /usr/local/bin/ash_query.py /usr/local/bin/ash_query
ln -s /usr/local/bin/_ash_log.py /usr/local/bin/_ash_log

Context (Environment)

Mac OS X 10.12.6
advanced shell history build from master branch (5ce11d2), I am using the python version.
zsh 5.2 (x86_64-apple-darwin16.0)

Missing ~/.ash/queries on install

After using make build_c; make install_c or make and make install, then following the sourcing instructions I received FAILED TO FIND A FILE TO PARSE! upon using ash_query.

Digging through the source I eventually found reference to $HOME/.ash/queries. touching this file made everything work as expected.

"FAILED TO FIND A FILE TO PARSE!"

Fresh build and install on an Ubuntu-22.04.1 system.

I added the following to my .bashrc

source /usr/local/etc/advanced-shell-history/config
export ASH_CFG_SYSTEM_QUERY_FILE
source /usr/local/lib/advanced_shell_history/sh/bash

source ~/.bashrc
Advanced Shell History enabled: session 1

ash_query -Q
FAILED TO FIND A FILE TO PARSE!

This snippet from src/queries.cpp is looking for files in /etc/ash/queries and $HOME/.ash/queries
/**

  • Loads the configured files looking for saved queries.
    */
    void Queries::lazy_load() {
    // Prevent multiple loads, but allow loads for on-demand use.
    static bool loaded = false;
    if (loaded) return;
    loaded = true;

LOG(DEBUG) << "Loading query files for saved queries.";

// Load these files, in this order.
query::files.push_back("/etc/ash/queries");
query::files.push_back(string(getenv("HOME")) + "/.ash/queries");

// Initialize the input file.
yyin = 0;
if (yywrap()) {
cout << "FAILED TO FIND A FILE TO PARSE!" << endl;
exit(1);
}

Neither of those queries files exist on my machine. Did I miss something in the build or installation steps?

"make build_c" fails on MacOS 10.12.6 with "undeclared identifier 'clock_nanosleep'"

Build fails with database.cpp:221:16: error: use of undeclared identifier 'clock_nanosleep'.

make build_c:

Generating man pages...
mkdir -p files//usr/share/man/man1
sed -e "s:__VERSION__:Version 0.8r2:" man/_ash_log.1 \
	  | sed -e "s:__DATE__:2018-01-03:" \
	  | gzip -9 -c > ./files/usr/share/man/man1/_ash_log.1.gz
sed -e "s:__VERSION__:Version 0.8r2:" man/ash_query.1 \
	  | sed -e "s:__DATE__:2018-01-03:" \
	  | gzip -9 -c > ./files/usr/share/man/man1/ash_query.1.gz
cp -af ./files/usr/share/man/man1/_ash_log.1.gz ./files/usr/share/man/man1/_ash_log.py.1.gz
cp -af ./files/usr/share/man/man1/ash_query.1.gz ./files/usr/share/man/man1/ash_query.py.1.gz
chmod 644 ./files/usr/share/man/man1/*ash*.1.gz
mkdir -p files//usr/local/bin
mkdir -p files//usr/local/etc/advanced-shell-history
mkdir -p files//usr/local/lib/advanced_shell_history/sh
chmod 755 files//usr/local/lib/advanced_shell_history/sh files//usr/local/etc/advanced-shell-history
cp shell/* files//usr/local/lib/advanced_shell_history/sh
cp config queries files//usr/local/etc/advanced-shell-history

Compiling source code...
gcc -DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_THREADSAFE=0 -c sqlite3.c
sqlite3.c:15855:17: warning: 'OSAtomicCompareAndSwapPtrBarrier' is deprecated: first deprecated in macOS 10.12 - Use
      atomic_compare_exchange_strong() from <stdatomic.h> instead [-Wdeprecated-declarations]
      success = OSAtomicCompareAndSwapPtrBarrier(NULL, newzone, 
                ^
/usr/include/libkern/OSAtomicDeprecated.h:547:6: note: 'OSAtomicCompareAndSwapPtrBarrier' has been explicitly marked
      deprecated here
bool    OSAtomicCompareAndSwapPtrBarrier( void *__oldValue, void *__newValue, void * volatile *__theValue );
        ^
1 warning generated.
g++ -c -g -Wall -DASH_VERSION="\"0.8r2\"" -ansi -pedantic -O2 -o _ash_log.o _ash_log.cpp -lrt
clang: warning: -lrt: 'linker' input unused [-Wunused-command-line-argument]
g++ -c -g -Wall -DASH_VERSION="\"0.8r2\"" -ansi -pedantic -O2 -o command.o command.cpp -lrt
clang: warning: -lrt: 'linker' input unused [-Wunused-command-line-argument]
g++ -c -g -Wall -DASH_VERSION="\"0.8r2\"" -ansi -pedantic -O2 -o config.o config.cpp -lrt
clang: warning: -lrt: 'linker' input unused [-Wunused-command-line-argument]
g++ -c -g -Wall -DASH_VERSION="\"0.8r2\"" -ansi -pedantic -O2 -o database.o database.cpp -lrt
clang: warning: -lrt: 'linker' input unused [-Wunused-command-line-argument]
database.cpp:221:16: error: use of undeclared identifier 'clock_nanosleep'
    int rval = clock_nanosleep(CLOCK_MONOTONIC, 0, &to_sleep, &remaining);
               ^
1 error generated.
make[1]: *** [database.o] Error 1
make: *** [build_c] Error 2

g++ --version:

Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 9.0.0 (clang-900.0.39.2)
Target: x86_64-apple-darwin16.7.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

Using without root

Installed this on my local machine and I really like it! Now I'd like to install it on a larger cluster where I don't have root access to install anything. What would I have to change to get it to install to a different directory?

Integration with starship

Ash is a great plugin and is what I have been looking for a while.

However it breaks my starship :(
Is it possible to get this and starship to work nicely together?

I had a play around adding it to .config/starship.toml but failed miserably.
I also had a look into the ASH source scripts - wow

Something to do with ...
https://starship.rs/advanced-config/#custom-pre-prompt-and-pre-execution-commands-in-bash
Or this error

Advanced Shell History enabled: session 39
❯ eval "$(starship init bash)"
bash: PROMPT_COMMAND: readonly variable

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.