Giter VIP home page Giter VIP logo

pycmd's Introduction

1. What is PyCmd?  
-----------------
PyCmd is a smart command prompt extension for Windows' cmd.exe; its purpose is
to emulate a few power features of UNIX shells (decent Tab-completion,
persistent history, etc.)

[Experimental] PyCmd now also runs on Linux, acting as a front-end for bash


2. What are some important features?
------------------------------------
 a. Tab completion 
    - when several completions are possible, list them (plain/bash- or
      interactive/zsh-style)
    - insert/remove quotes as needed
    - complete executables from the PATH and internal CMD.exe commands
    - complete names of environment variables, including pseudo-variables
    - complete wildcards
    - expand values of environment variables when completing
    - support both '/' and '\' as path separators

 b. Command suggestions
    - automatically suggest commands from history or from available
      completions:
        - accept with Right/End
        - accept partially with "forward-word" (Ctrl-Right etc.)
        - accept & run with Ctrl-Enter

 b. Command history
    - the history is persistent across PyCmd sessions
    - direct history search (type a few filter characters/words, then Up/Down)
    - incremental history search (Ctrl-R)
    - remove command from history (Ctrl-Alt-K)
    - history ordering is more intuitive than cmd's default strategy

 c. Command editing
    - support emacs key bindings
    - Copy-Paste using the keyboard (Ctrl-C/X/V or Emacs-style)
    - Undo/Redo with Ctrl-[Shift-]Z (regular style) or Ctrl-_ (Emacs-style)
    - dynamic, context-sensitive token expansion with Alt-/ (Emacs-style)
    - search string ([Shift-]F3)
    - smart word-by-word navigation
    - lexical selection (Shift-Up/Down)

 d. Navigation
    - history of recently visited directories (Alt-Left/Right/D on empty line)
    - cd to parent (Alt-Up)

 e. Other
    - smart prompt:
      - highlighted for readability
      - abbreviates path to save space
      - displays git and svn status
      - displays ERRORLEVEL (if > 0)
      - customizable
    - configuration file (init.py) for customizing colors, prompt etc.
    - Shift-PgUp/PgDn to scroll the buffer
    - expand/abbreviate ~ as %HOME% or %USERPROFILE%
    - Ctrl-D on an empty line closes PyCmd
    - show the current working directory in the window title


3. Known problems
-----------------
    - when DelayedExpansion is disabled (PyCmd.exe /V:OFF), %ERRORLEVEL% is not
      properly processed
    - DOSKEY macros are not supported
    - can NOT be used to fully replace cmd.exe as default shell (e.g. via 
      %COMSPEC%)


4. Future plans
---------------
    - custom TAB-completion for the arguments of common commands
    - clean-up the mechanism that dispatches commands to cmd.exe (currently kind 
      of hacky)


5. How do I download/install/run it?
------------------------------------   
 a. Download a binary distribution (created with cx_freeze, see
    https://pypi.org/project/cx-Freeze/) from
          https://github.com/horeah/PyCmd/releases
    Then, unpack and start PyCmd.exe. No installation is necessary.

 b. Clone the repository, then:
       (1) `python run_tests.py` to run tests
       (2) `python PyCmd.py` to start the application
           You will need:
               - Python 3.10+ from http://www.python.org/download/
               - The pywin32 package (pip install pywin32)
               - The pefile package (pip install pefile)
       (3) `make` to to build a binary distribution
           You will also need:
               - cx_freeze (pip install cx_freeze)
               - MinGW from http://www.mingw.org/ 


6. How do I report a crash/problem?
-----------------------------------
For bugs or feature requests, please use the bug tracker provided by GitHub
at https://github.com/horeah/PyCmd/issues

When reporting crashes, please try to locate and attach a crash log (look in
%APPDATA%\PyCmd for files named crash-yyyymmdd_hhmmss.log).


7. Credits
----------
   - The fish shell is an endless source of good ideas:
            https://fishshell.com/
   - fsm.py is a nice package for implementing a Finite State Machine:
            http://code.activestate.com/recipes/146262



---------------------------------------------------
Horea Haitonic (h o r e a h _at_ g m a i l . c o m)

pycmd's People

Contributors

bdumitriu avatar clackwell avatar horeah avatar santagada avatar spavid04 avatar ufo avatar

Stargazers

 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

pycmd's Issues

use prompt-toolkit

Hi,

Has prompt-toolkit been considered? It would give most of fish shell features missing, vim keybindings and more. The downside is moving token parsing and other infrastructure code to it.

I can give it a try next weekend if this an interesting path.

PyCmd on Linux (running on top of bash)

As an experiment, PyCmd can now also run on Linux (or WSL) as a front-end for bash; this issue is for collecting and tracking related feedback.

Rationale: while shells focused on user interaction do exist in the Linux world (e.g. fish, and also zsh in some regards) and they are way more advanced than PyCmd, there are still a few areas that PyCmd/Linux covers better (at least in my opinion):

  • Runs straight on top of bash, and therefore can directly run bash commands, source bash scripts etc. This means bash users (the vast majority of shell users in the world, for what it's worth) can use it straight-away with no additional learning or adaption.
  • Offers consistent interaction (appearance, completion, shortcuts etc.) across Windows (running on top of cmd) and Linux (running on top of bash). For users who need both (like I do for my $DAYJOB) this makes for reduced cognitive overhead.
  • The command search (both immediate filtering with the "Up" arrow and the modal "Ctrl-R" search) is more powerful and intuitive than what I (for one) have seen in other shells.
  • Completing wildcards is much more useful than the typical shell: the matching files are listed and can be selected interactively from the completion list.
  • The directory history (fish also offers some of this, but in a more rudimentary form).
  • Git & SVN-aware prompt out of the box
  • Friendlier editing (selection, undo, token expansion with Alt-/)
  • Pressing Esc pushes the command to the history; this doesn't sound like a lot but for me it is very helpful in practice (I often start typing a command, then realize I am in the wrong folder; I can press Esc, then cd to the correct directory, then use the Up arrow to retrieve the half-typed command).

There are a lot of things that are currently not working or need to be improved, of course; the most important ones are listed here:

  • Multi-line commands are not really supported
  • Running commands that produce a lot of output is much slower compared to a typical shell; this is because the output is intercepted by PyCmd and therefore processed in Python (this does open opportunities for interesting new features though; e.g. a shortcut that would copy the output of the previous command to the Clipboard).
  • Using the clipboard directly from PyCmd doesn't work for now; one must use the terminal copy/paste functionality like with any other shell
  • Shell variables (as opposed to exported variables) are not expanded when completing
  • Internal commands are not completed
  • Quoting is not properly accounted for when completing
  • Bracketed paste is disabled
  • ... more will probably be discovered along the way

One can try it out using release bundle "20230424-linux64", or by checking out branch "mesh" -- note that I consider this a "private" branch for now and might be still amending/rebasing; if someone wants to contribute, some prior coordination will be needed.

Ctrl+r for search

Hi,

Thanks so much for porting PyCMD to python 3 and moving to github!

I've tried the latest release here and while most seem to work it seems like Ctrl+R is not bind to search, and Shift + F3 also doesn't seem to work. Together with ctrl + a and ctrl + e and general up and down for history, history search on ctrl+r is my most used keybinding on bash. Is there a reason for it not being set?

Use actual Unicode width when computing the cell-width of strings printed to the terminal

This was initially reported by @santagada in the context of the incremental history search (#1) but applies to several other places in the code: assuming that the number of terminal cells is equal to the number of characters in the printed string is incorrect for certain classes of Unicode characters!

The suggested solution is to use a package like wcwidth (https://pypi.org/project/wcwidth/) whenever terminal sizes and offsets are being computed.

Interactive directory history

In order to allow for a longer directory history PyCmd should use an interactive, searchable Window (similar to the one used for zsh-style completions) when Alt-D is pressed.

New feature Ctrl-Alt-K (remove commands from the history) prevents typing characters via "Alt Gr"

Hi,
I finally updated PyCmd after a long time to get the latest great improvements. I personally find using CTRL-ALT-K very useful, but I immediately found out that I couldn't type characters like "~" oder "|" any longer, since for that I have to press "Alt Gr" on a german keyboard layout. The current implementation doesn't pass through any other keys pressed with CTRL+ALT. I could make a merge request, since it's an easy one.
Greets

Support emacs-style keybindings in interactive selection windows

In the selection window (e.g. when listing completions), accept Ctrl-P/N/F/B as an alternative to Up/Down/Right/Left and Ctrl-V/Alt-V as an alternative do PgDn/PgUp.

In addition: "entering" the interactive window after pressing Tab is now performed using the "Down" key; Ctrl-N should be accepted as an alternative.

Note: implementation-wise, I would go for a match-case statement. This might be a nice preview/proof-of-concept for using a match-case in the main key-dispatching loop in PyCmd.py (currently kind of messy)

Cd to an inexistent folder crashes PyCMD

C:\U\leonardo.santagada> cd Idon'texist


************************************
PyCmd has encountered a fatal error!

Traceback (most recent call last):
  File "PyCmd.py", line 555, in internal_cd
FileNotFoundError: [WinError 2] The system cannot find the file specified: b"Idon'texist"

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "PyCmd.py", line 774, in <module>
  File "PyCmd.py", line 526, in main
  File "PyCmd.py", line 587, in run_command
  File "PyCmd.py", line 558, in internal_cd
AttributeError: 'str' object has no attribute 'decode'

Crash report written to:
  C:\Users\leonardo.santagada\AppData\Roaming\PyCmd\crash-20230110_161154.log

Press any key to exit...
************************************

Provide a way to remove commands from history

Sometimes it is desirable to delete some earlier command from the history (e.g. it might contain sensitive information, or maybe it's just plain wrong and we don't want it to "pollute" the history).

This action could be triggered by some key combination (Ctrl-Shift-K?) while navigating the history (either via the current paradigm "type filter string, then Up" or possibly during incremental search as proposed by #1).

Implementing this is complicated because it requires cooperation between multiple running PyCmd instances: deleting from the current instance is not enough, as the other instances will still have it and save it in the history file. This is why the only manual workaround is currently to close all PyCmd processes for the current user, then manipulate the %APPDATA%\history file using some editor.

Ideas on how to implement this (ideally: in a simple way) are welcome ๐Ÿ˜„

Access is denied.

Every time I start this application, this was printed in the screen:

Access is denied.
Access is denied.
Access is denied.

Welcome to PyCmd 20240206-x64!


F:\Downloads\PC-20240206-w64\PyCmd>

The message "Access is denied." is also printed 3 times after every command that I run inside PyCmd!

App Version: 20240206
OS Version: Windows 10 x64

  • The last version (20230829) works fine!

Thanks.

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.