Coder Social home page Coder Social logo

cx's Introduction

cx

A directory history management utility written in C

History of cx

I wrote this a few years ago, and I actually use it very often even though I’ve long forgotten about its code (not that it’s hard to remember), so I thought I’d share it here. It’s actually proven to be very robust for me.

Its purpose is to be a very simple, shell-agnostic clone of z. I made it on FreeBSD and later modified to work on my Linux installs. The program has POSIX shell bindings, and specific bindings for csh, zsh and fish, which work more closely with the specific shell’s distinctive features. cx attempts to do cli directory management the right way where the right way can be defined, so that it can also be as portable as possible.

The original commit log is long gone in a crumbled mercurial repository on an erased VPS. So this is how I came to make this. I needed to keep a history of visited directories in a way that would work on any shell I used. I used tcsh on FreeBSD and zsh on Linux, I needed my tool to work on both. Where no POSIX shell standard will save us, what better way than to write an overly engineered but very barebones C program with a daemon-client architecture, to reassure yourself behind a few more layers of POSIX?

UPDATE No more daemon

Using cx

  • Include the script corresponding to your shell from /usr/local/share/cx/ in your shell's startup script (.bashrc, .cshrc, .zshrc and the likes)
  • Move around with cd to fill the database
  • Jump around with cx to known locations, priority is based on frecency (modify calculate_priority)
  • Non-existent directories are automatically removed from the database, so you don't need to maintain it

Installing

This program requires the SQLite3 development headers and library.

make && sudo make install should build and install the program to /usr/local by default. Defining the PREFIX environment variable will let you define where it's installed. Scripts for various shells are installed in ${PREFIX}/share/cx, which you should include for your respective shell to have convenient access to the cx command.

flags

  • -D : Specify the database path
  • -p : Add an entry representing this path, if it exists
  • -i : Specify the ID of the entry instead of looking up
  • -d: Dump the database's contents
  • -s: Set priority for the entry
  • -l: Lock the entry
  • -u: Unlock the entry
  • -t: Toggle the lock on the entry
  • -r: Remove the entry

cx's People

Contributors

colfrog avatar jpmens avatar

Stargazers

Thomas Leary avatar Swastik Acharyya avatar Fulvio Scapin avatar Igor Zubkov avatar Joseph Breihan avatar stavros vagionitis avatar birk avatar Rafael Kitover avatar Paul Tan avatar Pho Hale avatar Colin Dean avatar Birger J. Nordølum avatar  avatar Jeff Carpenter avatar Abdullah Atta avatar  avatar Neal Fultz avatar Cosmo avatar  avatar rusty kay avatar Sergey Naumov avatar Vincent Demeester avatar Ruslan Prakapchuk avatar  avatar Tulip Amalie avatar

Watchers

James Cloos avatar

Forkers

jpmens

cx's Issues

Start the daemon through the init system

As mentioned in #2, to run globally, the program has to be user-aware.

To do this, the protocol and the database need to be made user-aware. The cx data would be moved to ${PREFIX}/var/cx, and the folder would still contain the socket, the database and the lockfile.

Messages will have to be authentified through the socket in some way. I'm wondering if PAM might do it. Suggestions are welcome.

I'm also afraid that the added complexity that doing this might bring could undermine the beautiful simplicity of this software. If I thought that a complex directory history management utility was necessary in many people's workflow, I would probably keep the client in C and, at the very least, adapt the daemon to C++17 to build upon it, or build a completely new, compatible daemon using Raku or Rust, improving cxd.c separately as a smaller, high quality, option.

A suggestion about the bash shell script

As written, the cd function you provide doesn’t respect $?. An example:

# If the user has not sourced your cx.sh script
cd nonexistentdirectory
echo $?
1

# If the user has sourced your cx.sh script
cd nonexistentdirectory
echo $?
0

In the second case, $? shows the success or failure of the call to cxc -p "${PWD}".

I think the pattern you want is this, as seen here for example:

  cd() {
      builtin cd $@
      result=$?
      cxc -p "${PWD}"
      return $result
  }

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.