https://github.com/christarazi/pushpopdir
An alternative take on the pushd/popd utlilties -- C++ CLI program that uses a global stack to store the directories
https://github.com/christarazi/pushpopdir
cpp ipc popd pushd shared-memory stack
Last synced: 9 months ago
JSON representation
An alternative take on the pushd/popd utlilties -- C++ CLI program that uses a global stack to store the directories
- Host: GitHub
- URL: https://github.com/christarazi/pushpopdir
- Owner: christarazi
- License: gpl-3.0
- Created: 2015-12-30T00:59:33.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2017-08-12T03:43:13.000Z (almost 9 years ago)
- Last Synced: 2025-06-09T06:48:13.393Z (about 1 year ago)
- Topics: cpp, ipc, popd, pushd, shared-memory, stack
- Language: C++
- Homepage:
- Size: 43 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pushpopdir
A pushd/popd-like utility designed to behave exactly like `pushd` and
`popd` except with a global stack.
The stack is not bound by a terminal process unlike the original commands. You
can push a directory from one terminal process and pop it into another. I
developed this because it comes in handy when I have multiple terminals open.
## Info
- Utilizes IPC in form of shared memory. The stack is stored in shared memory
which makes it "global".
- The stack is set to a max of `100` elements.
- To make the popping utility work, a function in `.bashrc` needs to be added.
This is because the popping utility outputs the directory it has popped and a
child process (popping utility) cannot change the parent process's (terminal)
working directory. Therefore, we need to add a function to `.bashrc` so that
the terminal can capture the output of the popping utility and `cd` into it.
See more [here](http://unix.stackexchange.com/questions/14721/changing-current-working-dir-with-a-script).
## Installation
### Dependencies
- g++
- make
- bash (`configure.sh` is a bash script)
The default installation assumes bash is the default shell, but it is not a
requirement.
```shell
$ ./configure.sh
```
This will compile and install the tool. You will need sudo privileges for the
default installation directory. Then add the function below to your shell's
configuration file.
**Note:** If you are using a different shell other than `bash`, please add the
function above to your shell's respective configuration file, i.e. if you
are using `zsh`, then it would go in `.zshrc`.
```shell
# Function for wrapping the output of global_pop_dir so we can cd.
function gpopdir() {
if [ "$#" -eq 0 ]
then
cd "$(global_pop_dir)"
else
global_pop_dir "$@"
fi
}
```
## Usage
```shell
$ gpushdir # Push a directory onto the stack.
$ gpushdir -r # Deallocate the shared memory (stack).
$ gpopdir # Pop a directory from the stack and `cd` into it.
$ gpopdir -l # List contents of the stack from top to bottom.
```
## Todo
- ~~Remove the `-r` option and implement the deallocation of the shared memory
when the stack is being popped when empty.~~ No need for this as it can be
used to clear the stack.
- ~~Add ability to list the contents of the stack.~~
- ~~Add ability to clear the stack.~~ Deallocating the stack already does
this.
- Add ability to have multiple stacks.
- Include `-u` option for automatic updating of the program.
## Contribution
Please fork and submit a pull request. If you find a bug, submit an issue. I
welcome feedback as well.
## License
This program is free software, distributed under the terms of the [GNU] General
Public License as published by the Free Software Foundation, version 3 of the
License (or any later version). For more information, see the file LICENSE.