Skip to content

Commit

Permalink
Merge pull request #2 from Termina/dir-marks
Browse files Browse the repository at this point in the history
Dir marks
  • Loading branch information
csvwolf authored Aug 6, 2024
2 parents 00dbed5 + 8a7c601 commit 9851d6a
Show file tree
Hide file tree
Showing 8 changed files with 429 additions and 9 deletions.
50 changes: 46 additions & 4 deletions Cargo.lock

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

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ cli-clipboard = "0.4.0"
sysinfo = "0.30.12"
bytesize = {version = "1.2.0", features = ["serde"]}
parse-size = "1.0.0"
walkdir = "2"
walkdir = "2"
serde = "1.0.204"
serde_json = "1.0.120"
colored = "2.1.0"
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

> a bunch of commands for dev informations.
Install by cloning the demo and run:

```bash
cargo install --path .
```

### Usages

Install it with cargo install git source.
Expand Down Expand Up @@ -42,6 +48,34 @@ in large --min 1k --sort
5.7 MB ./target/release/deps/libserde-8238757ab41c1ecb.rlib
```

### Dir mark

```bash
in dir add demo # add a bookmark "demo" of current directory
in dir jump demo # jump to it
in dir ls # show all bookmarks
in dir rm demo # unlink it
code $(in dir lookup demo) # open it in vscode
```

Since every shell only allow `cd <dir>` from functions, you need to add extra code to you `.bashrc` or `.zshrc`:

```bash
in dir gg >> ~/.zshrc
```

or eval function directly:

```bash
eval "$(in dir gg)"
```

then jump to `demo` with:

```bash
gg demo
```

### License

MIT
76 changes: 76 additions & 0 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub enum InspectionCommand {
ShowProcesses(InspectForProcesses),
ShowWorkingDirectory(InspectForWorkingDirectory),
ListFileSize(InspectForFileSize),
DirMark(InspectForDirMark),
}

/// command for inspecting IP addresses.
Expand Down Expand Up @@ -65,3 +66,78 @@ pub struct InspectForFileSize {
#[argh(switch, short = 's')]
pub sort: bool,
}

/// command for directory marks
#[derive(FromArgs, PartialEq, Debug)]
#[argh(subcommand, name = "dir")]
pub struct InspectForDirMark {
#[argh(subcommand)]
pub subcommand: DirMarkCommand,
}

#[derive(FromArgs, PartialEq, Debug)]
#[argh(subcommand)]
pub enum DirMarkCommand {
Add(InspectForDirMarkAdd),
Remove(InspectForDirMarkRemove),
Search(InspectForDirMarkSearch),
Jump(InspectForDirMarkJump),
Lookup(InspectForDirMarkLookup),
ShellFn(InspectForDirMarkShellFn),
}

/// command for adding a directory mark
#[derive(FromArgs, PartialEq, Debug)]
#[argh(subcommand, name = "add")]
pub struct InspectForDirMarkAdd {
/// keyword
#[argh(positional)]
pub kwd: String,
/// description
#[argh(option)]
pub desc: Option<String>,
}

/// command for removing a directory mark
#[derive(FromArgs, PartialEq, Debug)]
#[argh(subcommand, name = "rm")]
pub struct InspectForDirMarkRemove {
/// keyword
#[argh(positional)]
pub kwd: String,
/// remove by path
#[argh(switch, short = 'p')]
pub by_path: bool,
}

/// command for searching a directory mark
#[derive(FromArgs, PartialEq, Debug)]
#[argh(subcommand, name = "ls")]
pub struct InspectForDirMarkSearch {
/// query
#[argh(positional)]
pub query: Option<String>,
}

/// command for jumping to a directory mark
#[derive(FromArgs, PartialEq, Debug)]
#[argh(subcommand, name = "jump")]
pub struct InspectForDirMarkJump {
/// keyword
#[argh(positional)]
pub kwd: String,
}

/// command for looking up a directory mark
#[derive(FromArgs, PartialEq, Debug)]
#[argh(subcommand, name = "lookup")]
pub struct InspectForDirMarkLookup {
/// keyword
#[argh(positional)]
pub kwd: String,
}

/// command for shell function
#[derive(FromArgs, PartialEq, Debug)]
#[argh(subcommand, name = "gg")]
pub struct InspectForDirMarkShellFn {}
9 changes: 9 additions & 0 deletions src/dir_mark_gg.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

function gg {
eval "in dir jump $1"
local target=/tmp/inspection-bashmarks-jump-target
if test -f $target; then
cd "$(cat $target)"
ls -pG
fi
}
Loading

0 comments on commit 9851d6a

Please sign in to comment.