srsudar / eg

Useful examples at the command line.
MIT License
1.8k stars 98 forks source link

custom-dir #67

Closed Sispheor closed 7 years ago

Sispheor commented 7 years ago

If I understand well, the custom-dir override a md file that is in the default-dir.

If I override the default-dir, I'll lose every md file pre installed by eg. Right?

From my understanding, I cannot have personal md files and keep the defaults one in the same time.

Sispheor commented 7 years ago

OK, the custom-dir should already allowing me that. Following the doc.. I don't know why, my file is listed in eg --list, but when I run eg <myfile> I have no output.

Sispheor commented 7 years ago

All files in my custom-dir are ignored. They appear in the list but no output for all of them.

Here an example of file

# SSL/TLS

check a ca certificate againt URL

    openssl s_client -CApath ca_cert.crt -connect https://url.example

Check a Certificate Signing Request (CSR)

    openssl req -text -noout -verify -in CSR.csr

Check a private key

    openssl rsa -in privateKey.key -check

Check a certificate

    openssl x509 -in certificate.crt -text -noout

# Generateate a self signed certificate

Generate private key

    openssl genrsa -out ca.key 2048

Generate CSR

    openssl req -new -key ca.key -out ca.csr

Generate Self Signed certificate

    openssl x509 -req -days 365 -in ca.csr -signkey ca.key -out ca.crt

# Others

Get CA certificate from server

    echo -n | openssl s_client -connect 37.59.53.15:443 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > /tmp/ca.cert

I'm on the last eg release 1.0.0 installed from pip.

srsudar commented 7 years ago

Custom files are supposed to appear before default files in the output, but both should be present. Their content will be separated by ---. I have some custom awk examples, eg, and this is my output from eg awk (truncated):

# Print All Fields

Print all fields:
    awk -F: ' { for (i = 1; i < NF; i++) print $i }'

Split lines into field on `:` (`-F:`).

Print all fields using a for loop. `NF` is the number of fields in the line,
`print $2` will print the second field.

This command will print your path, assuming it is colon-delimited:
    echo $PATH | awk -F: ' { for (i = 1; i < NF; i++) print $i }'

---

# awk

print lines matching `foo`
    awk '/foo/' input.txt

match foo, split on whitespace, and print the first element in the split array
    awk '/foo/ { print $1 }' input.txt

This is my egrc:

[eg-config]
custom-dir = ~/dotfiles/eg/custom_files

[color]
heading = '\x1b[38;5;172m'

My extra awk content is in ~/dotfiles/eg/custom_files/awk.md.

Can you post:

  1. The contents of your egrc
  2. The ls output of your custom directory
  3. The output of eg --list
Sispheor commented 7 years ago

Hi thanks for your answer

 cat .egrc 
[eg-config]
pager-cmd = 'less -RMFK'
custom-dir = ~/Documents/snippets

Content of ~/Documents/snippets

ls ~/Documents/snippets
git.md  ip.md  iptables.md  ldap.md  ssl.md

List from eg

Programs supported by eg: 
adb
----- TRUNCATED ---
git *
ip *
iptables +
ldap +
ssl +
----- TRUNCATED ---
Sispheor commented 7 years ago

Not that it works for IP and GIT, the content of my file has been added to the original one. But for LDAP, SSL and Iptable, they are listed but I have no output at all.

Sispheor commented 7 years ago

When you say "but both should be present." You mean that if I want to have a personal content, I need to add into an existing file provided by eg?

srsudar commented 7 years ago

Hmm nothing looks amiss to me there...

For most use cases (at least that I'm aware of), personal content should go in your custom directory. If you add content for a command that ships with eg, you should see both pieces of content concatenated together. Since git * is output from your eg --list command, eg is correctly noting that you have some custom git examples and that it also ships with git examples.

Based on the config you've provided, the output of eg git for you should be:

<the contents of ~/Documents/snippets/git.md>
---
<the default git examples>

It sounds like that is working for you, right?

The + in the output of eg --list is supposed to indicate that examples have been added (+) rather than modified (*) by the custom directory. Again based on your config, eg ssl should show the contents of your file ~/documents/snippets/ssl.md and nothing else.

*It sounds like you are seeing expected behavior for commands that show `, but getting no output for commands that show+`, is that correct?**

If so, a few more questions:

  1. have you modified anything in any of the eg-related directories installed by pip? Maybe aliases.json or something? This is unlikely, but just in case.
  2. Is behavior the same with the default pager-cmd? I thought I understood the X option on your other issue, but messing around with it I'm not sure I do. Maybe something is going on there that we're not handling gracefully. Try removing it from your egrc temporarily.
  3. Are you invoking the command simply as eg ssl?
  4. Are your custom examples on a networked or linked drive/directory? I don't think this should matter, but again maybe we're not handling it gracefully somewhere.
  5. What is the output of which -a eg?
  6. What is the output of eg --pager-cmd 'cat' ssl? Still no output?
Sispheor commented 7 years ago

Yes, if I have a custom content it works.

  1. No, no modification. Just fresh install from pip
  2. It works without the pager-cmd set in the egrc!
  3. yes
  4. no, local directory
  5. /usr/local/bin/eg
  6. It works to! I have an output!
Sispheor commented 7 years ago

The weird thing is that the X parameter doesn't disturb the program when I want to show a default example like awk.

To summarize, when I use this config: pager-cmd = 'less -RMFK'

srsudar commented 7 years ago

Is it a length of file thing? If less doesn't have to do any paging (ie it all fits on the screen at once) it terminates. Otherwise, you have to page. Maybe the X flag is opening less, paging the content, exiting less, then clearing the screen. If you make your terminal shorter does eg ssl work with your pager-cmd?

Sispheor commented 7 years ago

You are right, I've added some lines into the SSL file and it works. I removed the F flag(Scroll forward) and it works normally.

Sorry for having disturbed you with that. This is totally not a eg bug :)

Thank you for this tool anyway !

srsudar commented 7 years ago

Interesting. No worries and glad to hear it's resolved!