Skip to content

It wont find my previous ssh connections on bash/zsh #6

Open

Description

@piratx

Really glad to find this little useful utility for (recent) ssh connections.

I am trying to find out why I get a connect: empty list while I am using it on macos (10.14) with zsh.

I managed to run the ssh-history command (cat "$HISTFILE" | grep -E "^ssh\s" | sed -e 's/\s*$//' | sort | uniq -c | sort -nr | sed -e "s/^\s*[0-9]*\s//") on bash and I got the history lines contain ssh. But otherwise I cannot make it to work.

Activity

  1. added a commit that references this issue on Oct 12, 2020
  2. XpliSyL commented on Feb 19, 2021

    @XpliSyL

    Hey mate here is a working solution if your zsh history file looks like this :

    : 1612859817:0;composer require box/spout
    : 1612860397:0;serve
    : 1612864497:0;g stash
    : 1612864547:0;serve
    : 1612864918:0;git stash pop
    : 1612864923:0;serve
    : 1612865778:0;q
    : 1612867006:0;g stash
    : 1612867185:0;g stash pop
    : 1612867186:0;q
    : 1612867375:0;g stash
    : 1612868268:0;g stash pop
    : 1612875694:0;g status`

    Just change the ssh-history() function to :

    ssh-history() {
      cat "$HISTFILE" | grep -E "ssh\s" | sed 's/.*;//'| sed -e 's/\s*$//' | sort | uniq -c | sort -nr | sed -e "s/^\s*[0-9]*\s//"
    }
  3. piratx commented on Feb 19, 2021

    @piratx
    Author

    Thanks for replying @XpliSyL I am using my own alias shortcuts since 2019.
    But okay, I will use it now :)

    What about that list box, I tried to use it but it's just echoing?

  4. XpliSyL commented on Feb 19, 2021

    @XpliSyL

    I don't know much about list box. But as I understood list box just echo in a pleasant way the list that you give him.

    I had the same probem as yours as my list of last ssh connection was empty because of the wrong regex pattern in the sed.
    Correcting the line has resolved my problem.

  5. piratx commented on Feb 19, 2021

    @piratx
    Author

    Hmm, I corrected the ssh-history line on ssh-connect.sh but I am still having an empty list here.. do I need to check my alias or something?

    I am just doing ssh-connect from the same directory :/

  6. XpliSyL commented on Feb 19, 2021

    @XpliSyL

    I guess that your zsh history file is different than mine...
    So the line that I corrected is still not working with your history format :/

    Show me the output of this command :
    (:warning: Don't copy the lines that you don't want to share !!)

    cat $HISTFILE | head -n 5

    And I'll find the right regex sed expression that you need.

  7. piratx commented on Feb 19, 2021

    @piratx
    Author

    Hmm, this is what I get:

    : 1592623475:0;defaults write -g NSFileViewer -string info.filesmanager.Files\
    
    : 1592696533:0;brew install lzip
    : 1592696601:0;brew install b3sum
    : 1592697145:0;brew install oniguruma
    
  8. XpliSyL commented on Feb 19, 2021

    @XpliSyL

    Hmmmm it's definitly the same format. So if your history file contain some commands like

    ssh username@ssh.server.com

    It should return the line.

    When you do :

    cat $HISTFILE | grep ssh

    Do you have some ssh commands ?

    My last hypothesis would be that list box might not work on your system (macos). I tested it in debian and I don't have any problem.

    If the last commands return you some ssh lines and list box don't show them then I won't be able to help you anymore :(

  9. backl1n commented on Oct 12, 2021

    @backl1n

    salut jutilise oh my zsh jai installer le plugin en manuelle dans le dossier /opt et quand jexecute il ne maffiche pas le connection ssh avant pourtant quand jaffiche mon $histfile jai bien mon historique peut tu maider stp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions