Giter Club home page Giter Club logo

eg's Introduction

eg

Useful examples at the command line.

Build Status

Overview

eg provides examples of common uses of command line tools.

Man pages are great. How does find work, again? man find will tell you, but you'll have to pore through all the flags and options just to figure out a basic usage. And what about using tar? Even with the man pages tar is famously inscrutable without the googling for examples.

No more!

eg will give you useful examples right at the command line. Think of it as a companion tool for man.

eg comes from exempli gratia, and is pronounced like the letters: "ee gee".

eg Demo

Installation

With pip

pip install eg

With brew

brew install eg-examples

Run from source

Clone the repo and create a symlink to eg_exec.py. Make sure the location you choose for the symlink is on your path:

git clone https://github.com/srsudar/eg ./
ln -s /absolute/path/to/eg-repo/eg_exec.py /usr/local/bin/eg

Note that the location of eg_exec.py changed in version 0.1.x in order to support Python 3 as well as 2. Old symlinks will print a message explaining the change, but you'll have to update your links to point at the new location. Or you can install with pip or brew.

eg doesn't ship with a binary. Dependencies are very modest and should not require you to install anything (other than pytest if you want to run the tests). If you find otherwise, open an issue.

Usage

eg <program>

eg takes an argument that is the name of a program for which it contains examples.

eg find will provide examples for the find command.

eg --list will show all the commands for which eg has examples.

The complete usage statement, as shown by eg --help, is:

eg [-h] [-v] [-f CONFIG_FILE] [-e EXAMPLES_DIR] [-c CUSTOM_DIR] [-p PAGER_CMD]
   [-l] [--color] [-s] [--no-color] [program]

How it Works

Files full of examples live in examples/. A naming convention is followed such that the file is the name of the tool with .md. E.g. the examples for find are in find.md.

eg find will pipe the contents of find.md through less (although it tries to respect the PAGER environment variable).

Configuration and Extension

eg works out of the box, no configuration required.

If you want to get fancy, however, eg can be fancy.

For example, maybe a team member always sends you bzipped tarballs and you can never remember the flag for bzipping--why can't that guy just use gzip like everybody else? You can create an example for untarring and unzipping bzipped tarballs, stick it in a file called tar.md, and tell eg where to find it.

The way to think about what eg does is that it takes a program name, for example find, and looks for files named find.md in the default and custom directories (including subdirectories). If it finds them, it pipes them through less, with the custom files at the top. Easy.

The default and custom directories can be specified at the command line like so:

eg --examples-dir='the/default/dir' --custom-dir='my/fancy/dir' find

Instead of doing this every time, you can define a configuration file. It must begin with a section called eg-config and can contain two keys: custom-dir and examples-dir. Here is an example of a valid config file:

[eg-config]
examples-dir = ~/examples-dir
custom-dir = ~/my/fancy/custom/dir

The config file is looked for first at ${XDG_CONFIG_HOME}/eg/egrc and then at ~/.egrc. You can also specify a different location at the command line like so:

eg --config-file=myfile find

Editing Your Custom Examples

If you want to edit one of your custom examples, you can edit the file directly or you can just use the -e or --edit flag.

To edit your find examples, for example, you could say:

eg -e find

This will dump you into an editor. The contents will be piped before the default examples the next time you run eg find.

Formatting Output

eg is highly customizable when it comes to output. You have three ways to try and customize what is piped out the pager, applied in this order:

  1. Color
  2. Squeezing out excess blank lines
  3. Regex-based substitutions

Color

eg is colorful. The default colors were chosen to be pretty-ish while boring enough to not create problems for basic terminals. If you want to override these colors, you can do so in the egrc in a color section.

Things that can be colored are:

  • pound: pound sign before headings
  • heading: the text of headings
  • code: anything indented four spaces other than a leading $
  • prompt: a $ that is indented four spaces
  • backticks: anything between two backticks

Values passed to these options must be string literals. This allows escape characters to be inserted as needed. An egrc with heading text a nice burnt orange might look like this:

[eg-config]
custom-dir = ~/my/fancy/custom/dir

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

To remove color altogether, for example if the color formatting is messing up your output somehow, you can either pass the --no-color flag to eg, or you can add an option to your egrc under the eg-config section like so:

[eg-config]
color = false

Squeezing Blank Lines

The example files use a lot of blank lines to try and be readable at a glance. Not everyone likes this many blank lines. If you hate all duplicate lines, you can use your favorite pager to remove all duplicate commands, like:

eg --pager-cmd 'less -sR' find

This will use less -sR to page, which will format color correctly (-R) and remove all duplicate blank lines (-s).

eg also provides its own custom squeezed output format, removing all blank lines within a single example and only putting duplicate blank lines between sections. This can be configured at the command line with --squeeze or in the egrc with the squeeze option, like:

[eg-config]
squeeze = true

Running eg --squeeze find removes excess newlines like so:

Squeezed Output

Regex Substitutions

Additional changes to the output can be accomplished with regular expressions and the egrc. Patterns and replacements are applied using Python's re module, so look to the documentation for specifics. Substitutions should be specified in the egrc as a list with the syntax: [pattern, replacement, compile_as_multiline]. If compile_as_multiline is absent or False, the pattern will not be compiled as multiline, which affects the syntax expected by re. The re.sub method is called with the compiled pattern and replacement.

Substitutions must be named and must be in the [substitutions] section of the egrc. For example, this would remove all the four-space indents beginning lines:

[substitutions]
remove-indents = ['^    ', '', True]

This powerful feature can be used to perform complex transformations, including support additional coloring of output beyond what is supported natively by eg. If you wish there was an option to remove or add blank lines, color something new, remove section symbols, etc, this is a good place to start.

If multiple substitutions are present, they are sorted by alphabetically by name before being applied.

Paging

By default, eg pages using less -RMFXK. The -R switch tells less to interpret ANSI escape sequences like color rather than showing them raw. -M tells it to show line number information in the bottom of the screen. -F to automatically quit if the entire example fits on the screen. -X tells it not to clear the screen. Finally, -K makes less exit in response to Ctrl-C.

You can specify a different pager using the --pager-cmd option at the command line or the pager-cmd option in the egrc. If specified in the egrc, the value must be a string literal. For example, this egrc would use cat to page:

[eg-config]
pager-cmd = 'cat'

pydoc.pager() does a lot of friendly error checking, so it might still be useful in some situations. If you want to use pydoc.pager() to page, you can pass the pydoc.pager as the pager-cmd.

Format and Content of Examples

Example documents are written in markdown. Documents in markdown are easily read at the command line as well as online. They all follow the same basic format.

This section explains the format so that you better understand how to quickly grok the examples.

Contributors should also pay close attention to these guidelines to keep examples consistent.

Overview

Anything indented four spaces or surrounded by backticks `like this` are meant to be input or output at the command line. A single line indented four spaces is a user-entered command. If a block is indented four spaces, only the lines beginning with $ are user-entered--anything else is output.

Name of the Command

The first section heading should be simply the name of the tool. It should be followed by the most rudimentary examples. Users that are familiar with the command but just forget the precise syntax should be able to see what they need without scrolling. Example commands should be as real-world as possible, with file names and arguments as illustrative as possible. Examples for the cp command, for instance, might be:

cp original.txt copy.txt

Here the .txt extensions indicate that these are file names, while the names themselves make clear which is the already existing file and which will be the newly created copy.

This section shouldn't show output and should not include the $ to indicate that we are at the command line.

This section should be a quick glance for users that know what the tool does, know a basic usage is what they are trying to do, and are just looking for a reminder.

Basic Usage

Next a Basic Usage section explains the most basic usage without using real file names. This section gives users that might not know the usual syntax a more abstract example than the first section. It is intended to provide a more useful explanation than the first entry in the man page, which typically shows all possible flags and arguments in a way that is not immediately obvious to new users of the command. The SYNOPSIS section of the man page for cp, for example, shows:

cp [-R [-H | -L | -P]] [-fi | -n] [-apvX] source_file ... target_directory

The Basic Usage is intended to provide less verbose, more immediately practical versions of the man page's SYNOPSIS section.

Commands and flags that will affect the behavior are shown as would be entered in the command line, while user-entered filenames and arguments that do not alter the command's behaviors are shown in < >. Examples in the Basic Usage section for the cp command, for instance, might be:

cp -R <original_directory> <copied_directory>

In this command the cp -R indicate the command and behavior and thus are not given in < >. Case-dependent components of the command, in this case the directory to be copied and the name of the copy, are surrounded with < >. Each is wrapped in separate < > to make clear that it is in fact two distinct arguments.

Additional Sections

Subsequent subsections can be added for common uses of the tools, as appropriate.

Formatting

Although markdown is readable, it can still be tricky without syntax highlighting. We use spacing to help the eye.

  1. All code snippets are followed by at two blank lines, unless overruled by 2.

  2. Each line beginning a section (i.e. the first character on the line is #) should be preceded by exactly three lines.

  3. Files should end with two blank lines.

  4. Lines should not exceed 80 characters, unless to accommodate a necessarily long command or long output.

Contributing

Additions of new tools and new or more useful examples are welcome. eg should be something that people want to have on their machines. If it has a man page, it should be included in eg.

Please read the Format of Examples section and review existing example files to get a feel for how eg pages should be structured.

If you find yourself turning to the internet for the same command again and again, consider adding it to the examples.

eg examples do not intend to replace man pages! man is useful in its own right. eg should provide quick examples in practice. Do not list all the flags for the sake of listing them. Assume that users will have man available.

Building and Running Tests

eg depends only on standard libraries and Python 2.x/3.x, so building should be a simple matter of cloning the repo and running the executable eg/eg.py.

eg uses pytest for testing, so you'll have to have it installed to run tests. Once you have it, run py.test from the root directory of the repo.

Tests should always be expected to pass. If they fail, please open an issue, even if only so that we can better elucidate eg's dependencies.

Grace Hopper Approves

Alias eg to woman for something that is like man but a little more practical:

$ alias woman=eg
$ man find
$ woman find

eg's People

Contributors

ajwalkiewicz avatar bdellaterra avatar brobin avatar dflamand avatar dgm9704 avatar kritts avatar lijingjiang avatar lirt avatar louis-riviere-xyz avatar maclandrol avatar mayanksuman avatar mcarton avatar milouse avatar momeni avatar moyiz avatar nawer avatar scorphus avatar sispheor avatar smmoosavi avatar srsudar avatar tyhawkins avatar vanillajonathan 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

eg's Issues

Examples don't respect links

@mcarton has begun adding examples with symbolic links for aliases like netcat and nc, which are the same command. #21 and #22 are two examples. This is a good idea, and something I'd thought about doing for link and ln as well, but didn't.

The system currently isn't following these links, so this approach is failing.

Can we put symbolic links in a repo and have windows as well as *nix systems respect them? I need to look into this. If it's possible, I'll have to update the code to obey it. If not, we'll have to think of something else.

Bash completion

Hi @srsudar,

Please add bash completion (TAB) for eg:

eg fi<TAB>
eg find

I don't know how is the best way to implement that functionality, but as eg is a terminal tool the tab completion is a necessary feature.

compatibility with Python3

In python 3.4 (or any Python3 envs) we got:

Traceback (most recent call last):
  File "/usr/bin/eg", line 3, in <module>
    from eg import eg_exec
  File "/usr/lib/python3.4/site-packages/eg/eg_exec.py", line 74
    print 'you must specify a program or pass the --list or --version flags'
                                                                           ^
SyntaxError: Missing parentheses in call to 'print'

TLDR.sh updates

How are you feeding updates from TLDR.sh into eg ?

Why don't you name TLDR.sh in your readme?

Easily edit example files

It would be great to have shorthand to edit example files. For instance:

$ eg -c <c> edit <program>

would be equivalent to

$ $EDITOR <c>/<program>.md

(This particular syntax might be a bit ambiguous)

Formatting is wrong in Msysgit's bash on Windows

Shows like this:

The system cannot find the path specified.
?[30m?[1m#?[0m?[31m?[1m tar?[0m

extract .tar file

    ?[36m?[1m?[0m?[32m?[1mtar vfx archive.tar?[0m


unzip and extract .tar.gz or .tgz file

    ?[36m?[1m?[0m?[32m?[1mtar vfxz g_zipped_archive.tar.gz?[0m


turn directory into a .tar file

    ?[36m?[1m?[0m?[32m?[1mtar vfc tarred_directory.tar directory?[0m


turn directory into g-zipped directory

    ?[36m?[1m?[0m?[32m?[1mtar vfcz z_zipped_directory.tar.gz directory?[0m

Better and convenient custom functionnality

Hey!

Why not create a custom dir and include its content by default ?
And add it to .gitigore

This way we can git clone, create our very custom in this folder, commit them to our personnal repo, and from time to time git pull this original repo to get updates.

What do you think about it ?

custom-dir

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.

Add `eg shutdown` and `eg reboot`

For reboot I use sudo reboot
For shutdown I've been taught to use sudo shutdown -h now but I don't know why I was taught -h vs -P so I tried using eg shutdown to find out what most people use. Unfortunately it doesn't exist. Maybe someone more knowledgeable than I can write an example for it.

Error installing on mac os

Hi,

First of all, i want to thank you for your great job.

I have a problem installing eg on mac os yosemite. I use python-2.7.9. When installing eg i got this error :

You are using pip version 6.1.0, however version 6.1.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Collecting eg
  Downloading eg-0.0.3.tar.gz
Installing collected packages: eg
  Running setup.py install for eg
    Complete output from command /usr/local/opt/python/bin/python2.7 -c "import setuptools, tokenize;__file__='/private/var/folders/6r/1yy2rml521q84_4mbl7qlgkw0000gq/T/pip-build-SquNOd/eg/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /var/folders/6r/1yy2rml521q84_4mbl7qlgkw0000gq/T/pip-0SWL60-record/install-record.txt --single-version-externally-managed --compile:
    /usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'test_requires'
      warnings.warn(msg)
    running install
    running build
    running build_py
    creating build
    creating build/lib
    creating build/lib/eg
    copying eg/__init__.py -> build/lib/eg
    copying eg/eg_colorizer.py -> build/lib/eg
    copying eg/eg_config.py -> build/lib/eg
    copying eg/eg_exec.py -> build/lib/eg
    copying eg/eg_util.py -> build/lib/eg
    creating build/lib/eg/examples
    copying eg/examples/awk.md -> build/lib/eg/examples
    copying eg/examples/cat.md -> build/lib/eg/examples
    copying eg/examples/cd.md -> build/lib/eg/examples
    copying eg/examples/chmod.md -> build/lib/eg/examples
    copying eg/examples/chown.md -> build/lib/eg/examples
    copying eg/examples/cp.md -> build/lib/eg/examples
    copying eg/examples/curl.md -> build/lib/eg/examples
    copying eg/examples/cut.md -> build/lib/eg/examples
    copying eg/examples/du.md -> build/lib/eg/examples
    copying eg/examples/find.md -> build/lib/eg/examples
    copying eg/examples/gcc.md -> build/lib/eg/examples
    copying eg/examples/grep.md -> build/lib/eg/examples
    copying eg/examples/hexdump.md -> build/lib/eg/examples
    copying eg/examples/ifconfig.md -> build/lib/eg/examples
    copying eg/examples/kill.md -> build/lib/eg/examples
    copying eg/examples/less.md -> build/lib/eg/examples
    copying eg/examples/ln.md -> build/lib/eg/examples
    copying eg/examples/locate.md -> build/lib/eg/examples
    copying eg/examples/ls.md -> build/lib/eg/examples
    copying eg/examples/mkdir.md -> build/lib/eg/examples
    copying eg/examples/more.md -> build/lib/eg/examples
    copying eg/examples/mv.md -> build/lib/eg/examples
    copying eg/examples/od.md -> build/lib/eg/examples
    copying eg/examples/ps.md -> build/lib/eg/examples
    copying eg/examples/pwd.md -> build/lib/eg/examples
    copying eg/examples/rm.md -> build/lib/eg/examples
    copying eg/examples/scp.md -> build/lib/eg/examples
    copying eg/examples/sort.md -> build/lib/eg/examples
    copying eg/examples/su.md -> build/lib/eg/examples
    copying eg/examples/sudo.md -> build/lib/eg/examples
    copying eg/examples/tar.md -> build/lib/eg/examples
    copying eg/examples/top.md -> build/lib/eg/examples
    copying eg/examples/touch.md -> build/lib/eg/examples
    copying eg/examples/tr.md -> build/lib/eg/examples
    copying eg/examples/wc.md -> build/lib/eg/examples
    copying eg/examples/whatis.md -> build/lib/eg/examples
    copying eg/examples/whereis.md -> build/lib/eg/examples
    copying eg/examples/which.md -> build/lib/eg/examples
    copying eg/examples/xargs.md -> build/lib/eg/examples
    running build_scripts
    creating build/scripts-2.7
    copying and adjusting bin/eg -> build/scripts-2.7
    changing mode of build/scripts-2.7/eg from 644 to 755
    running install_lib
    creating /usr/local/lib/python2.7/site-packages/eg
    copying build/lib/eg/__init__.py -> /usr/local/lib/python2.7/site-packages/eg
    copying build/lib/eg/eg_colorizer.py -> /usr/local/lib/python2.7/site-packages/eg
    copying build/lib/eg/eg_config.py -> /usr/local/lib/python2.7/site-packages/eg
    copying build/lib/eg/eg_exec.py -> /usr/local/lib/python2.7/site-packages/eg
    copying build/lib/eg/eg_util.py -> /usr/local/lib/python2.7/site-packages/eg
    creating /usr/local/lib/python2.7/site-packages/eg/examples
    copying build/lib/eg/examples/awk.md -> /usr/local/lib/python2.7/site-packages/eg/examples
    copying build/lib/eg/examples/cat.md -> /usr/local/lib/python2.7/site-packages/eg/examples
    copying build/lib/eg/examples/cd.md -> /usr/local/lib/python2.7/site-packages/eg/examples
    copying build/lib/eg/examples/chmod.md -> /usr/local/lib/python2.7/site-packages/eg/examples
    copying build/lib/eg/examples/chown.md -> /usr/local/lib/python2.7/site-packages/eg/examples
    copying build/lib/eg/examples/cp.md -> /usr/local/lib/python2.7/site-packages/eg/examples
    copying build/lib/eg/examples/curl.md -> /usr/local/lib/python2.7/site-packages/eg/examples
    copying build/lib/eg/examples/cut.md -> /usr/local/lib/python2.7/site-packages/eg/examples
    copying build/lib/eg/examples/du.md -> /usr/local/lib/python2.7/site-packages/eg/examples
    copying build/lib/eg/examples/find.md -> /usr/local/lib/python2.7/site-packages/eg/examples
    copying build/lib/eg/examples/gcc.md -> /usr/local/lib/python2.7/site-packages/eg/examples
    copying build/lib/eg/examples/grep.md -> /usr/local/lib/python2.7/site-packages/eg/examples
    copying build/lib/eg/examples/hexdump.md -> /usr/local/lib/python2.7/site-packages/eg/examples
    copying build/lib/eg/examples/ifconfig.md -> /usr/local/lib/python2.7/site-packages/eg/examples
    copying build/lib/eg/examples/kill.md -> /usr/local/lib/python2.7/site-packages/eg/examples
    copying build/lib/eg/examples/less.md -> /usr/local/lib/python2.7/site-packages/eg/examples
    copying build/lib/eg/examples/ln.md -> /usr/local/lib/python2.7/site-packages/eg/examples
    copying build/lib/eg/examples/locate.md -> /usr/local/lib/python2.7/site-packages/eg/examples
    copying build/lib/eg/examples/ls.md -> /usr/local/lib/python2.7/site-packages/eg/examples
    copying build/lib/eg/examples/mkdir.md -> /usr/local/lib/python2.7/site-packages/eg/examples
    copying build/lib/eg/examples/more.md -> /usr/local/lib/python2.7/site-packages/eg/examples
    copying build/lib/eg/examples/mv.md -> /usr/local/lib/python2.7/site-packages/eg/examples
    copying build/lib/eg/examples/od.md -> /usr/local/lib/python2.7/site-packages/eg/examples
    copying build/lib/eg/examples/ps.md -> /usr/local/lib/python2.7/site-packages/eg/examples
    copying build/lib/eg/examples/pwd.md -> /usr/local/lib/python2.7/site-packages/eg/examples
    copying build/lib/eg/examples/rm.md -> /usr/local/lib/python2.7/site-packages/eg/examples
    copying build/lib/eg/examples/scp.md -> /usr/local/lib/python2.7/site-packages/eg/examples
    copying build/lib/eg/examples/sort.md -> /usr/local/lib/python2.7/site-packages/eg/examples
    copying build/lib/eg/examples/su.md -> /usr/local/lib/python2.7/site-packages/eg/examples
    copying build/lib/eg/examples/sudo.md -> /usr/local/lib/python2.7/site-packages/eg/examples
    copying build/lib/eg/examples/tar.md -> /usr/local/lib/python2.7/site-packages/eg/examples
    copying build/lib/eg/examples/top.md -> /usr/local/lib/python2.7/site-packages/eg/examples
    copying build/lib/eg/examples/touch.md -> /usr/local/lib/python2.7/site-packages/eg/examples
    copying build/lib/eg/examples/tr.md -> /usr/local/lib/python2.7/site-packages/eg/examples
    copying build/lib/eg/examples/wc.md -> /usr/local/lib/python2.7/site-packages/eg/examples
    copying build/lib/eg/examples/whatis.md -> /usr/local/lib/python2.7/site-packages/eg/examples
    copying build/lib/eg/examples/whereis.md -> /usr/local/lib/python2.7/site-packages/eg/examples
    copying build/lib/eg/examples/which.md -> /usr/local/lib/python2.7/site-packages/eg/examples
    copying build/lib/eg/examples/xargs.md -> /usr/local/lib/python2.7/site-packages/eg/examples
    byte-compiling /usr/local/lib/python2.7/site-packages/eg/__init__.py to __init__.pyc
    byte-compiling /usr/local/lib/python2.7/site-packages/eg/eg_colorizer.py to eg_colorizer.pyc
    byte-compiling /usr/local/lib/python2.7/site-packages/eg/eg_config.py to eg_config.pyc
    byte-compiling /usr/local/lib/python2.7/site-packages/eg/eg_exec.py to eg_exec.pyc
    byte-compiling /usr/local/lib/python2.7/site-packages/eg/eg_util.py to eg_util.pyc
    running install_egg_info
    running egg_info
    writing eg.egg-info/PKG-INFO
    writing top-level names to eg.egg-info/top_level.txt
    writing dependency_links to eg.egg-info/dependency_links.txt
    warning: manifest_maker: standard file '-c' not found

    reading manifest file 'eg.egg-info/SOURCES.txt'
    writing manifest file 'eg.egg-info/SOURCES.txt'
    Copying eg.egg-info to /usr/local/lib/python2.7/site-packages/eg-0.0.3-py2.7.egg-info
    running install_scripts
    copying build/scripts-2.7/eg -> /usr/local/bin
    error: [Errno 62] Too many levels of symbolic links: '/usr/local/bin/eg'

    ----------------------------------------
    Command "/usr/local/opt/python/bin/python2.7 -c "import setuptools, tokenize;__file__='/private/var/folders/6r/1yy2rml521q84_4mbl7qlgkw0000gq/T/pip-build-SquNOd/eg/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /var/folders/6r/1yy2rml521q84_4mbl7qlgkw0000gq/T/pip-0SWL60-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/var/folders/6r/1yy2rml521q84_4mbl7qlgkw0000gq/T/pip-build-SquNOd/eg

Thanks

No recognize config path: $HOME/.config/eg/egrc

Version: 1.2.0
Installed from pip

I follow the information on README of the repository. For custom config file I create a file called egrc on the next path: skabit/.config/eg, but nothing happens. In this file I only add a custom directory with my examples:

[eg-config]
# Lines starting with # are treated as comments
custom-dir = ~/docu/cheats

[substitutions] section is being ignored

Substitution from README doesn't work:
~/.egrc

[substitution]
remove-indents = ['^    ', '', True]

Applying following patch:

diff --git a/eg/substitute.py b/eg/substitute.py
index b19f457..8eb006e 100644
--- a/eg/substitute.py
+++ b/eg/substitute.py
@@ -1,6 +1,6 @@
 import re
-
-
+import sys
+print('Imported Substitution', file=sys.stderr)
 class Substitution:
     """
     A substitution to be performed on a piece of text.
@@ -19,6 +19,7 @@ class Substitution:
         self.pattern = pattern
         self.repl = replacement
         self.is_multiline = is_multiline
+        print(self,file=sys.stderr)
 
     def apply_and_get_result(self, string):
         """
@@ -31,6 +32,12 @@ class Substitution:
             compiled_pattern = re.compile(self.pattern)
 
         result = re.sub(compiled_pattern, self.repl, string)
+        print(f'Did sub change anything? {result != string}',file=sys.stderr)
+        if result != string:
+            with open(f'orig.{hash(self.repl)}', 'w') as f:
+                f.write(string)
+            with open(f'subbed.{hash(self.repl)}', 'w') as f:
+                f.write(result)
         return result
 
     def __eq__(self, other):

If eg-config.squeeze = false causes following output:

Imported Substitution

while eg-config.squeeze = true causes:

Imported Substitution
<eg.substitute.Substitution object at 0x7f55c8029730>
<eg.substitute.Substitution object at 0x7f55c7bb63d0>
<eg.substitute.Substitution object at 0x7f55c7bb61c0>
Did sub change anything? True
Did sub change anything? True
Did sub change anything? False

[substitutions] section is completely ignored. Adding and removing entries from it doesn't cause above output to change. This is also confirmed by diffing orig.* and subbed.* files - only change is occasional newline removed (it looks like squeeze is done with Substitution).

Tested on latest git version with ./eg_exec.py ls >/dev/null.

Custom pager fails to load in script/function

In the file ~/.config/eg, I have:

[eg-config]
pager-cmd = 'cat'

Running eg less displays relevant information and returns me to the command line.

In a zsh function, I have:

describe_app () {
    if [ "$1" != "" ]; then
        man -f $1;
        eg $1;
        tldr $1;
        cheat $1;
    fi
}

Running describe_app less displays relevant information, but when eg runs it displays in less and does not return to the command line.

eg do not support XDG_CONFIG_HOME

eg configuration is saved in ~/.egrc. I think eg should support XDG_CONFIG_HOME specification and save its configuration file in XDG_CONFIG_HOME.

Make configs TOML-compatible

For instance instead of:

[eg-config]
examples-dir = ~/examples-dir
custom-dir = ~/my/fancy/custom/dir

write:

[eg-config]
examples-dir = "~/examples-dir"
custom-dir = "~/my/fancy/custom/dir"

Maybe it's just a documentation mistake and configs are already written in TOML.

python x.7 code will break py3.7

eg/eg/color.py

Line 90 in f296847

compiled_pattern = re.compile(pattern, re.MULTILINE)

One of the color functions only checks if python version is < x.7. However python3.7 is now the default py version so this might start breaking systems with newer python executables.

    def _color_helper(s, text, pattern, repl):
        # < 2.7 didn't have the flags named argument.
        if sys.version_info[1] < 7:
            compiled_pattern = re.compile(pattern, re.MULTILINE)
            return re.sub(
                compiled_pattern,
                repl,
                text
            )
        else:
            return re.sub(
                pattern,
                repl,
                text,
                flags=re.MULTILINE
)

So couldn't we do
if sys.version_info < (2,7):

And be more explicit?

Maybe advise "pip install --user"

Hi,

I always look for ways to advertise pip install --user and I believe eg to be very user specific, so maybe it makes sense to change the README to say the following:

Installation

With pip For Your User

pip install --user
echo 'PATH=$PATH:$HOME/.local/bin' >> $HOME/.bashrc
exec $SHELL

What do you think?

Cheers,
Felix

PS: For those interested here is the talk where I got this idea from: Youtube / PyVideo

Option to remove or squeeze blank lines

I arbitrarily set the number of blank lines in examples based on what was easy for me to visually parse with and without color. It's been pointed out by @cool-RR that this might be gratuitous and not the best use of screen real estate.

I like the idea of a --squeeze option that removes some of the blank lines. I'm not sure the best way to do this. Some output options I might like to support are:

1: a single blank line between all examples in a section, two lines between sections:

# tar

extract a file

    tar vfxz blah

show file contents

    tar vft blah

another example

    tar blah


# Basic Usage (notice two lines above this)

Blah blah blah.

2: Blank lines between sections, no blanks between examples (this might actually look terrible, not sure):

# tar

extract a file
    tar vfxz blah

show file contents
    tar vft blah

another example
    tar blah


# Basic Usage (notice two lines above this)

Blah blah blah.

Hmm, so maybe the places it would make sense to squeeze would be:

  • between sections (i.e. the things that begin with #)
  • within an example (although this might look ugly, as shown in number 2 up there)
  • between examples (as shown in number 1)

I'm trying to think of ways that would make sense to specify this. Maybe something like --squeeze to make everything one line, and something like --squeeze [0, 1, 2] to put 0 blank lines within an example, 1 between examples, and two between sections, if we wanted to keep it highly customizable. I like some of the blank lines and don't want to throw them out entirely.

eg is not installed

Hello, I tried installing eg on ubuntu 14.04 :
git clone https://github.com/srsudar/eg
ln -s eg/eg/eg_exec.py /usr/local/bin/eg
tried the example
eg find
it returns :
Le programme « eg » n'est pas encore installé. Vous pouvez l'installer en tapant : sudo apt-get install easygit
in english :
the "eg" program is not installed yet. You can install it by typing : sudo apt-get install easygit
Any idea of what's wrong ?
Thanks

Recursive custom-dir

Hi,

I would like to classify my md files in directories like:

~/eg
~/eg/glossary
~/eg/tech

and in my config file, just having something like:

custom-dir=~/eg

Actually, when a md file is in a subdirectory, it is not found. Is there a way to change that ?

Thanks.

missing configuration key in the doc of the egrc

I would like eg to clean the screen after exit. Currently you use the "X" argument here to prevent the cleanup.
I can override the DEFAULT_PAGER_CMD by using [-p PAGER_CMD] but I have to type it everytime.
It would be useful to add this argument to the egrc.

[SOLVED] [TerminalIPythonApp] WARNING | File not found: u'/usr/bin/eg/eg_exec.py'

Hi, first, congrats and thanks for this very helpfull program.
But I have a small problem after installing it with pip on Ubuntu (15.04), I always get this

payen:~$ sudo pip install eg

Downloading/unpacking eg
Downloading eg-0.1.1.tar.gz
Running setup.py (path:/tmp/pip-build-Skmbws/eg/setup.py) egg_info for package eg
/usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'test_requires'
warnings.warn(msg)
Installing collected packages: eg
Running setup.py install for eg
/usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'test_requires'
warnings.warn(msg)
changing mode of build/scripts-2.7/eg from 644 to 755
changing mode of /usr/local/bin/eg to 755
Successfully installed eg
Cleaning up...

payen:~$ eg tar

[TerminalIPythonApp] WARNING | File not found: u'/usr/bin/eg/eg_exec.py'

What did I did wrong ?

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.