From 68a426216d38db0fe286c479c96406a8e31e3be8 Mon Sep 17 00:00:00 2001
From: Ajeet D'Souza <98ajeet@gmail.com>
Date: Thu, 5 Mar 2020 18:39:32 +0530
Subject: [PATCH] Initial commit
---
.gitignore | 16 ++++++
Cargo.toml | 25 +++++++++
LICENSE | 7 +++
src/config.rs | 1 +
src/db.rs | 122 ++++++++++++++++++++++++++++++++++++++++++++
src/dir.rs | 61 ++++++++++++++++++++++
src/error.rs | 32 ++++++++++++
src/main.rs | 127 ++++++++++++++++++++++++++++++++++++++++++++++
src/types.rs | 3 ++
src/util.rs | 74 +++++++++++++++++++++++++++
zoxide.plugin.zsh | 27 ++++++++++
11 files changed, 495 insertions(+)
create mode 100644 .gitignore
create mode 100644 Cargo.toml
create mode 100644 LICENSE
create mode 100644 src/config.rs
create mode 100644 src/db.rs
create mode 100644 src/dir.rs
create mode 100644 src/error.rs
create mode 100644 src/main.rs
create mode 100644 src/types.rs
create mode 100644 src/util.rs
create mode 100644 zoxide.plugin.zsh
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..1315c82
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,16 @@
+# Created by https://www.gitignore.io/api/rust
+# Edit at https://www.gitignore.io/?templates=rust
+
+### Rust ###
+# Generated by Cargo
+# will have compiled files and executables
+/target/
+
+# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
+# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
+Cargo.lock
+
+# These are backup files generated by rustfmt
+**/*.rs.bk
+
+# End of https://www.gitignore.io/api/rust
diff --git a/Cargo.toml b/Cargo.toml
new file mode 100644
index 0000000..e9f0ca0
--- /dev/null
+++ b/Cargo.toml
@@ -0,0 +1,25 @@
+[package]
+name = "zoxide"
+version = "0.1.0"
+authors = ["Ajeet D'Souza <98ajeet@gmail.com>"]
+description = "A cd command that learns your habits"
+repository = "https://github.com/ajeetdsouza/zoxide/"
+edition = "2018"
+
+keywords = ["cli"]
+categories = ["command-line-utilities", "filesystem"]
+license = "MIT"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
+bincode = "1.2.1"
+clap = "2.33.0"
+dirs = "2.0.2"
+failure = "0.1.6"
+fs2 = "0.4.3"
+serde = { version = "1.0.104", features = ["derive"] }
+
+[profile.release]
+codegen-units = 1
+lto = "fat"
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..fd94bad
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,7 @@
+Copyright 2020 Ajeet D'Souza
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/src/config.rs b/src/config.rs
new file mode 100644
index 0000000..df4c5e6
--- /dev/null
+++ b/src/config.rs
@@ -0,0 +1 @@
+pub const DB_PATH: &str = "_ZO_DBPATH";
diff --git a/src/db.rs b/src/db.rs
new file mode 100644
index 0000000..1eff26d
--- /dev/null
+++ b/src/db.rs
@@ -0,0 +1,122 @@
+use crate::dir::Dir;
+use crate::error::AppError;
+use crate::types::Timestamp;
+use failure::ResultExt;
+use serde::{Deserialize, Serialize};
+use std::fs::File;
+use std::io::{self, BufReader, BufWriter};
+use std::io::{Read, Write};
+use std::path::Path;
+use fs2::FileExt;
+
+#[derive(Debug, Default, Deserialize, Serialize)]
+pub struct DB {
+ pub dirs: Vec