forked from mirrors/deskwhich
Compare commits
No commits in common. "ad29e9ebcc9c227d38aaa9a4ce6301fd6d28e93c" and "cbe8a0cdf4bdbb26faecb028e79ad6c409376051" have entirely different histories.
ad29e9ebcc
...
cbe8a0cdf4
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,5 +1,3 @@
|
|||||||
/target
|
/target
|
||||||
*~
|
*~
|
||||||
.*~undo-tree~*
|
.*~undo-tree~*
|
||||||
result
|
|
||||||
.idea
|
|
||||||
|
26
flake.lock
26
flake.lock
@ -1,26 +0,0 @@
|
|||||||
{
|
|
||||||
"nodes": {
|
|
||||||
"nixpkgs": {
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1716097317,
|
|
||||||
"narHash": "sha256-1UMrLtgzielG/Sop6gl6oTSM4pDt7rF9j9VuxhDWDlY=",
|
|
||||||
"owner": "NixOS",
|
|
||||||
"repo": "nixpkgs",
|
|
||||||
"rev": "8535fb92661f37ff9f0da3007fbc942f7d134b41",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"id": "nixpkgs",
|
|
||||||
"ref": "nixpkgs-unstable",
|
|
||||||
"type": "indirect"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"root": {
|
|
||||||
"inputs": {
|
|
||||||
"nixpkgs": "nixpkgs"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"root": "root",
|
|
||||||
"version": 7
|
|
||||||
}
|
|
84
flake.nix
84
flake.nix
@ -1,84 +0,0 @@
|
|||||||
{
|
|
||||||
description = "confwhich: easily obtain info about XDG_CONFIG useage";
|
|
||||||
|
|
||||||
inputs.nixpkgs.url = "nixpkgs/nixpkgs-unstable";
|
|
||||||
|
|
||||||
outputs =
|
|
||||||
{ nixpkgs, ... }:
|
|
||||||
let
|
|
||||||
systems = [
|
|
||||||
"x86_64-linux"
|
|
||||||
"aarch64-linux"
|
|
||||||
];
|
|
||||||
|
|
||||||
forAllSystems = f: nixpkgs.lib.genAttrs systems (system: f system);
|
|
||||||
in
|
|
||||||
{
|
|
||||||
devShells = forAllSystems (
|
|
||||||
system:
|
|
||||||
let
|
|
||||||
pkgs = nixpkgs.legacyPackages.${system};
|
|
||||||
overrides = (builtins.fromTOML (builtins.readFile ./rust-toolchain.toml));
|
|
||||||
libPath =
|
|
||||||
with pkgs;
|
|
||||||
lib.makeLibraryPath [
|
|
||||||
|
|
||||||
];
|
|
||||||
in
|
|
||||||
{
|
|
||||||
default = pkgs.mkShell {
|
|
||||||
buildInputs = with pkgs; [
|
|
||||||
llvmPackages.bintools
|
|
||||||
rustup
|
|
||||||
];
|
|
||||||
RUSTC_VERSION = overrides.toolchain.channel;
|
|
||||||
# https://github.com/rust-lang/rust-bindgen#environment-variables
|
|
||||||
LIBCLANG_PATH = pkgs.lib.makeLibraryPath [ pkgs.llvmPackages_latest.libclang.lib ];
|
|
||||||
shellHook = ''
|
|
||||||
export PATH=$PATH:''${CARGO_HOME:-~/.cargo}/bin
|
|
||||||
export PATH=$PATH:''${RUSTUP_HOME:-~/.rustup}/toolchains/$RUSTC_VERSION-x86_64-unknown-linux-gnu/bin/
|
|
||||||
'';
|
|
||||||
|
|
||||||
# Add precompiled library to rustc search path
|
|
||||||
RUSTFLAGS = (
|
|
||||||
builtins.map (a: ''-L ${a}/lib'') [
|
|
||||||
# add libraries here (e.g. pkgs.libvmi)
|
|
||||||
]
|
|
||||||
);
|
|
||||||
LD_LIBRARY_PATH = libPath;
|
|
||||||
# Add glibc, clang, glib, and other headers to bindgen search path
|
|
||||||
BINDGEN_EXTRA_CLANG_ARGS =
|
|
||||||
# Includes normal include path
|
|
||||||
(builtins.map (a: ''-I"${a}/include"'') [
|
|
||||||
# add dev libraries here (e.g. pkgs.libvmi.dev)
|
|
||||||
pkgs.glibc.dev
|
|
||||||
])
|
|
||||||
# Includes with special directory paths
|
|
||||||
++ [
|
|
||||||
''-I"${pkgs.llvmPackages_latest.libclang.lib}/lib/clang/${pkgs.llvmPackages_latest.libclang.version}/include"''
|
|
||||||
''-I"${pkgs.glib.dev}/include/glib-2.0"''
|
|
||||||
''-I${pkgs.glib.out}/lib/glib-2.0/include/''
|
|
||||||
];
|
|
||||||
packages = with pkgs; [
|
|
||||||
# base toolchain
|
|
||||||
pkg-config
|
|
||||||
rustup
|
|
||||||
nil
|
|
||||||
];
|
|
||||||
};
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
packages = forAllSystems (
|
|
||||||
system:
|
|
||||||
let
|
|
||||||
pkgs = nixpkgs.legacyPackages.${system};
|
|
||||||
deskwhich-pkg = (pkgs.callPackage ./nix/package.nix { });
|
|
||||||
in
|
|
||||||
{
|
|
||||||
deskwhich = deskwhich-pkg;
|
|
||||||
default = deskwhich-pkg;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,17 +0,0 @@
|
|||||||
{ lib, rustPlatform }:
|
|
||||||
rustPlatform.buildRustPackage {
|
|
||||||
pname = "deskwhich";
|
|
||||||
version = "unstable-2024-05-19";
|
|
||||||
src = lib.cleanSource ../.;
|
|
||||||
|
|
||||||
cargoHash = "sha256-l7xlDrAvPtf+747DWRLu2d/O0Thvj6gKtoMksGmj02o=";
|
|
||||||
|
|
||||||
meta = {
|
|
||||||
description = "tool to find the path of desktop entries";
|
|
||||||
homepage = "https://codeberg.org/axtlos/deskwhich";
|
|
||||||
license = lib.licenses.gpl3Only;
|
|
||||||
mainProgram = "deskwhich";
|
|
||||||
maintainers = with lib.maintainers; [ grimmauld ];
|
|
||||||
platforms = lib.platforms.linux;
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,2 +0,0 @@
|
|||||||
[toolchain]
|
|
||||||
channel = "stable"
|
|
@ -3,9 +3,11 @@
|
|||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use clap_stdin::MaybeStdin;
|
use clap_stdin::MaybeStdin;
|
||||||
|
|
||||||
|
|
||||||
#[derive(Debug, Parser)]
|
#[derive(Debug, Parser)]
|
||||||
#[clap(name="deskwhich", version=env!("CARGO_PKG_VERSION"),about=env!("CARGO_PKG_DESCRIPTION"), author=env!("CARGO_PKG_AUTHORS"))]
|
#[clap(name="deskwhich", version=env!("CARGO_PKG_VERSION"),about=env!("CARGO_PKG_DESCRIPTION"), author=env!("CARGO_PKG_AUTHORS"))]
|
||||||
pub struct Cli {
|
pub struct Cli {
|
||||||
|
|
||||||
/// The desktop file to search for
|
/// The desktop file to search for
|
||||||
pub search: MaybeStdin<String>,
|
pub search: MaybeStdin<String>,
|
||||||
|
|
||||||
@ -22,6 +24,7 @@ pub struct Cli {
|
|||||||
pub all: bool,
|
pub all: bool,
|
||||||
|
|
||||||
//show_dot: bool,
|
//show_dot: bool,
|
||||||
|
|
||||||
/// Output a tilde for HOME directory
|
/// Output a tilde for HOME directory
|
||||||
#[arg(long, default_value_t=false)]
|
#[arg(long, default_value_t=false)]
|
||||||
pub show_tilde: bool,
|
pub show_tilde: bool,
|
||||||
|
32
src/main.rs
32
src/main.rs
@ -1,17 +1,17 @@
|
|||||||
// SPDX-License-Identifier: GPL-3.0-only
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
mod args;
|
mod args;
|
||||||
use crate::args::Cli;
|
|
||||||
use clap::Parser;
|
|
||||||
use std::env;
|
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
use std::env;
|
||||||
use std::process::exit;
|
use std::process::exit;
|
||||||
|
use clap::Parser;
|
||||||
|
use crate::args::Cli;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let cli = Cli::parse();
|
let cli = Cli::parse();
|
||||||
|
|
||||||
let args: Vec<String> = env::args().collect();
|
let args: Vec<String> = env::args().collect();
|
||||||
let xdg_data_dirs = std::env::var("XDG_DATA_DIRS").unwrap();
|
let xdg_data_dirs = std::env::var("XDG_DATA_DIRS").unwrap();
|
||||||
let data_dirs = xdg_data_dirs.split(':');
|
let data_dirs = xdg_data_dirs.split(":");
|
||||||
|
|
||||||
let mut found = false;
|
let mut found = false;
|
||||||
let home = match env::var("HOME") {
|
let home = match env::var("HOME") {
|
||||||
@ -19,8 +19,8 @@ fn main() {
|
|||||||
Err(_) => exit(1),
|
Err(_) => exit(1),
|
||||||
};
|
};
|
||||||
for dirs in data_dirs {
|
for dirs in data_dirs {
|
||||||
if (dirs.starts_with(&home) && cli.skip_home) || (dirs.starts_with('.') && cli.skip_dot) {
|
if (dirs.starts_with(&home) && cli.skip_home) || (dirs.starts_with(".") && cli.skip_dot) {
|
||||||
continue;
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
let files = match fs::read_dir(format!("{}/applications",dirs)) {
|
let files = match fs::read_dir(format!("{}/applications",dirs)) {
|
||||||
@ -28,27 +28,19 @@ fn main() {
|
|||||||
Err(_) => continue,
|
Err(_) => continue,
|
||||||
};
|
};
|
||||||
for file in files {
|
for file in files {
|
||||||
let desktop_file = file
|
let desktop_file = format!("{}", file.as_ref().unwrap().file_name().into_string().unwrap());
|
||||||
.as_ref()
|
let mut name = desktop_file.split(".");
|
||||||
.unwrap()
|
if name.find(|x| *x == cli.search.strip_suffix(".desktop").unwrap_or(&cli.search)).is_some() {
|
||||||
.file_name()
|
|
||||||
.into_string()
|
|
||||||
.unwrap()
|
|
||||||
.to_string();
|
|
||||||
let mut name = desktop_file.split('.');
|
|
||||||
if name
|
|
||||||
.any(|x| x == cli.search.strip_suffix(".desktop").unwrap_or(&cli.search))
|
|
||||||
{
|
|
||||||
let path = file.as_ref().unwrap().path();
|
let path = file.as_ref().unwrap().path();
|
||||||
let out = if cli.show_tilde {
|
let out = if cli.show_tilde {
|
||||||
path.display().to_string().replace(&home, "~").to_string()
|
format!("{}", path.display().to_string().replace(&home, "~"))
|
||||||
} else {
|
} else {
|
||||||
path.display().to_string()
|
path.display().to_string()
|
||||||
};
|
};
|
||||||
println!("{out}");
|
println!("{}", out);
|
||||||
found = true;
|
found = true;
|
||||||
if !cli.all {
|
if !cli.all {
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user