Skip to content

Commit

Permalink
Add Git Integration (issue lsd-rs#7)
Browse files Browse the repository at this point in the history
* Enabled using `cargo build --feature=git`
* git block is by default on the left of name block
* use `lsd --git --long` to enable git status info (only available on long display)
* sort by git status using `lsd --sort=git --long`
  • Loading branch information
hpwxf committed Mar 7, 2021
1 parent 34d12bf commit 5fb28e6
Show file tree
Hide file tree
Showing 23 changed files with 927 additions and 38 deletions.
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ matrix:
# Stable channel.
- os: linux
rust: stable
env: TARGET=x86_64-unknown-linux-gnu
env: TARGET=x86_64-unknown-linux-gnu FEATURES=git
- os: linux
rust: stable
env: TARGET=i686-unknown-linux-gnu
Expand All @@ -19,7 +19,7 @@ matrix:
env: TARGET=i686-unknown-linux-musl
- os: osx
rust: stable
env: TARGET=x86_64-apple-darwin
env: TARGET=x86_64-apple-darwin FEATURES=git
- os: linux
rust: stable
env:
Expand All @@ -30,13 +30,13 @@ matrix:
# The other platforms are disabled in order to reduce the total CI time
- os: linux
rust: beta
env: TARGET=x86_64-unknown-linux-gnu
env: TARGET=x86_64-unknown-linux-gnu FEATURES=git

# Nightly channel.
# The other platforms are disabled in order to reduce the total CI time
- os: linux
rust: nightly
env: TARGET=x86_64-unknown-linux-gnu
env: TARGET=x86_64-unknown-linux-gnu FEATURES=git

# Minimum Rust supported channel.
- os: linux
Expand Down
147 changes: 147 additions & 0 deletions Cargo.lock

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

10 changes: 9 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,18 @@ xdg = "2.1.*"
yaml-rust = "0.4.*"
serde = { version = "1.0", features = ["derive"] }
serde_yaml = "0.8"
log = { version = "0.4", features = ["release_max_level_error"] }

[target.'cfg(unix)'.dependencies]
users = "0.11.*"

[target.'cfg(windows)'.dependencies]
winapi = {version = "0.3.*", features = ["aclapi", "accctrl", "winnt", "winerror", "securitybaseapi", "winbase"]}
winapi = { version = "0.3.*", features = ["aclapi", "accctrl", "winnt", "winerror", "securitybaseapi", "winbase"] }

[dependencies.git2]
version = "0.13"
optional = true
default-features = false

[dependencies.clap]
features = ["suggestions", "color", "wrap_help"]
Expand All @@ -55,4 +61,6 @@ tempfile = "3"
serial_test = "0.5"

[features]
default = []
sudo = []
git = ["git2"]
2 changes: 1 addition & 1 deletion ci/before_deploy.bash
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
set -ex

build() {
cargo build --target "$TARGET" --release --verbose
cargo build --target "$TARGET" --features="$FEATURES" --release --verbose
}

pack() {
Expand Down
27 changes: 23 additions & 4 deletions src/app.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use clap::{App, Arg};

pub fn build() -> App<'static, 'static> {
App::new("lsd")
let app = App::new("lsd")
.version(crate_version!())
.about(crate_description!())
.arg(Arg::with_name("FILE").multiple(true).default_value("."))
Expand Down Expand Up @@ -192,7 +192,14 @@ pub fn build() -> App<'static, 'static> {
Arg::with_name("sort")
.long("sort")
.multiple(true)
.possible_values(&["size", "time", "version", "extension"])
.possible_values(&[
"size",
"time",
"version",
"extension",
#[cfg(feature = "git")]
"git",
])
.takes_value(true)
.value_name("WORD")
.overrides_with("timesort")
Expand Down Expand Up @@ -234,13 +241,15 @@ pub fn build() -> App<'static, 'static> {
"name",
"inode",
"links",
#[cfg(feature = "git")]
"git",
])
.help("Specify the blocks that will be displayed and in what order"),
)
.arg(
Arg::with_name("classic")
.long("classic")
.help("Enable classic mode (no colors or icons)"),
.long("classic")
.help("Enable classic mode (no colors or icons)"),
)
.arg(
Arg::with_name("no-symlink")
Expand Down Expand Up @@ -271,7 +280,17 @@ pub fn build() -> App<'static, 'static> {
.long("dereference")
.multiple(true)
.help("When showing file information for a symbolic link, show information for the file the link references rather than for the link itself"),
);
if cfg!(feature = "git") {
app.arg(
Arg::with_name("git")
.long("git")
.multiple(true)
.help("Show git status on file and directory")
)
} else {
app
}
}

fn validate_date_argument(arg: String) -> Result<(), String> {
Expand Down
Loading

0 comments on commit 5fb28e6

Please sign in to comment.