Skip to content

Commit

Permalink
v0.3.7
Browse files Browse the repository at this point in the history
  • Loading branch information
j-morano committed Feb 2, 2023
1 parent da24d69 commit 5413242
Show file tree
Hide file tree
Showing 14 changed files with 82 additions and 32 deletions.
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
.idea/
cz/target
Session.vim
target
2 changes: 1 addition & 1 deletion cz/Cargo.lock → Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cz/Cargo.toml → Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cz"
version = "0.3.6"
version = "0.3.7"
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
60 changes: 39 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,24 @@ Linux-only.
- Bash
- Zsh

### Install using binary release (recommended)
### Install/update using installation script (recommended)

To install `cz`, you can just run the installation script `install`.

You can download the script from the following URL:
- <https://raw.githubusercontent.com/j-morano/contemporary-z/main/z.sh>

To see the different installation options, you can just type:
```shell
./install --help
```

The default installation path is `$HOME/.local/bin/`.

> NOTE: in order to execute it, the script must be executable, so the command `chmod +x install` may be needed.

### Install manually using binary release

To install the program using the binary release, copy and paste the following commands in your terminal.

Expand All @@ -42,18 +59,18 @@ To install the program using the binary release, copy and paste the following co
```shell
wget https://github.com/j-morano/contemporary-z/releases/latest/download/cz
chmod +x cz
cp cz $HOME/.local/bin/
mv cz $HOME/.local/bin/
wget https://raw.githubusercontent.com/j-morano/contemporary-z/main/z.fish
mkdir -p $HOME/.config/fish/functions
cp z.fish $HOME/.config/fish/functions
mv z.fish $HOME/.config/fish/functions
```

#### Bash/Zsh

```shell
wget https://github.com/j-morano/contemporary-z/releases/latest/download/cz
chmod +x cz
cp cz $HOME/.local/bin/
mv cz $HOME/.local/bin/
wget https://raw.githubusercontent.com/j-morano/contemporary-z/main/z.sh
cat z.sh >> $HOME/.bashrc
```
Expand All @@ -63,17 +80,17 @@ cat z.sh >> $HOME/.bashrc
```shell
wget https://github.com/j-morano/contemporary-z/releases/latest/download/cz
chmod +x cz
cp cz $HOME/.local/bin/
mv cz $HOME/.local/bin/
```

### Install from source
### Install manually from source

To install `cz` from source, it is required to have installed [Cargo](https://doc.rust-lang.org/cargo/), the Rust _package manager_. You can install Rust, with `rustc` and `cargo`, following the instructions on [this](https://www.rust-lang.org/tools/install) page or from the official repositories of your distribution.

If this requirement is met, it is only necessary to clone the repository and run the specific installation script for the desired shell.


#### Debian-based distros:
#### Debian-based distros

In Debian-based distros (like Ubuntu), it is necessary to install the `build-essential` meta-package:

Expand All @@ -88,39 +105,37 @@ In Arch-based distros, it is necessary to install the `base-devel` meta-package:
sudo pacman -S base-devel
```

#### Repository cloning
#### Clone the repository

Using SSH:
```shell
git clone [email protected]:sonarom/contemporary-z.git
```

Using HTTPS:
```shell
git clone https://github.com/sonarom/contemporary-z.git
git clone https://github.com/j-morano/contemporary-z.git
```

#### Install using Cargo

```shell
$HOME/.cargo/bin/cargo install --path cz
$HOME/.cargo/bin/cargo install --path .
```

Then, depending on the shell, do the following.

> NOTE: ensure that `$HOME/.cargo/bin/` is in `$PATH`.
Then, depending on the shell, do the following.

> NOTE: You must be inside the repository folder (`contemporary-z`) to run the commands as shown below.
#### Fish

Add the function to fish functions.

```shell
mkdir -p $HOME/.config/fish/functions
cp z.fish $HOME/.config/fish/functions
mv z.fish $HOME/.config/fish/functions
```

#### Bash/Zsh

Add the code from `z.sh` to `.bashrc`. For example:

```shell
cat z.sh >> $HOME/.bashrc
```
Expand All @@ -130,9 +145,12 @@ cat z.sh >> $HOME/.bashrc
The default alias of Contemporary-z is `z`. However, if a different alias is preferred, it can be easily changed in the installation scripts. Hereafter, `cz` refers to the entire application, and `z` refers to the command.


### Usage:
### Usage

To see the usage of `cz`, you can just run it with the `--help` argument.

```
$ z --help
Usage: z [OPTION]... [DIRECTORY|SUBSTRING]...
FUNCTIONALITY:
Expand Down Expand Up @@ -183,7 +201,7 @@ Exit status:
0 if OK,
1 if minor problems (e.g., cannot access subdirectory)
Full documentation <https://github.com/sonarom/contemporary-z>
Full documentation <https://github.com/j-morano/contemporary-z>
```


Expand Down
44 changes: 39 additions & 5 deletions install
Original file line number Diff line number Diff line change
Expand Up @@ -25,46 +25,80 @@ parser.add_argument(
parser.add_argument(
'--source',
action='store_true',
help='Install from source'
)
parser.add_argument(
'--update',
action='store_true',
help='Update existing installation'
)
args = parser.parse_args()

args.path = expandvars(args.path)


if args.source:
os.system("git clone https://github.com/sonarom/contemporary-z.git")
os.system("$HOME/.cargo/bin/cargo install --path contemporary-z/cz")
if not os.path.exists('Cargo.toml'):
print('Cloning repository.')
os.system("git clone https://github.com/sonarom/contemporary-z.git")
src_path = 'contemporary-z'
else:
src_path = '.'
print('Installing using Cargo.')
os.system(f"$HOME/.cargo/bin/cargo install --path {src_path}")
else:
print('Downloading binary.')
request.urlretrieve(
"https://github.com/j-morano/contemporary-z/releases/latest/download/cz",
"cz"
)
print('Making binary executable.')
st = os.stat('cz')
os.chmod('cz', st.st_mode | 0o0111)
if os.path.exists(os.path.join(args.path, 'cz')):
print('Removing existing binary.')
os.remove(os.path.join(args.path, 'cz'))
print('Adding new binary.')
shutil.move('cz', args.path)

if not args.update:
if 'bash' in args.shell or 'zsh' in args.shell:
print('Installing cz for bash shell.')
print(' - Downloading z.sh.')
request.urlretrieve(
"https://raw.githubusercontent.com/j-morano/contemporary-z/main/z.sh",
"z.sh"
)
with open('z.sh', 'r') as fp:
zsh_contents = fp.read()

bashrc_path = expandvars("$HOME/.bashrc")
with open(bashrc_path, 'r') as fp:
matches = re.findall("z\(\)", fp.read())
if len(matches) == 0:
print(' - Adding z function to bashrc.')
with open(bashrc_path, 'a') as fp:
fp.write(zsh_contents)
else:
print('Warning: z function already exists in .bashrc, so it was not added.')
elif 'fish' in args.shell:
print('Installing cz for fish shell.')
print(' - Downloading z.fish.')
request.urlretrieve(
"https://raw.githubusercontent.com/j-morano/contemporary-z/main/z.fish",
"z.fish"
)
Path("$HOME/.config/fish/functions").mkdir(parents=True, exist_ok=True)
shutil.copyfile('z.fish', expandvars('$HOME/.config/fish/functions/z.fish'))
print(' - Creating fish functions directory if it does not exist.')
Path(
expandvars("$HOME/.config/fish/functions")
).mkdir(parents=True, exist_ok=True)
print(' - Copying z.fish to fish functions directory.')
shutil.copyfile(
'z.fish',
expandvars('$HOME/.config/fish/functions/z.fish')
)

print('Done! Please restart your shell.')
print(
'Then, you can check if contemporary-z is correctly installed by running:'
'\n$ z --version'
)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion cz/src/strings.rs → src/strings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,5 @@ Exit status:
0 if OK,
1 if minor problems (e.g., cannot access subdirectory)
Full documentation <https://github.com/sonarom/contemporary-z>
Full documentation <https://github.com/j-morano/contemporary-z>
";
File renamed without changes.

0 comments on commit 5413242

Please sign in to comment.