Update for latest fzf and add a few additional scripts

This commit is contained in:
Konstantin Nazarov 2023-05-14 18:24:43 +01:00
parent f9731dd7ca
commit fe69664195
Signed by: knazarov
GPG key ID: 4CFE0A42FA409C22
8 changed files with 285 additions and 204 deletions

36
flake.nix Normal file
View file

@ -0,0 +1,36 @@
{
description = "Nix q.sh dev environment";
# Flake inputs
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs";
};
# Flake outputs
outputs = { self, nixpkgs }:
let
# Systems supported
allSystems = [
"x86_64-linux" # 64-bit Intel/AMD Linux
"aarch64-linux" # 64-bit ARM Linux
"x86_64-darwin" # 64-bit Intel macOS
"aarch64-darwin" # 64-bit ARM macOS
];
# Helper to provide system-specific attributes
forAllSystems = f: nixpkgs.lib.genAttrs allSystems (system: f {
pkgs = import nixpkgs { inherit system; };
});
in
{
# Development environment output
devShells = forAllSystems ({ pkgs }: {
default = pkgs.mkShell {
# The Nix packages provided in the environment
packages = with pkgs; [
fzf
];
};
});
};
}

6
q
View file

@ -1,4 +1,4 @@
#!/bin/bash #!/bin/sh
# #
# Distributed under the terms of the BSD License # Distributed under the terms of the BSD License
# #
@ -32,7 +32,7 @@ if [[ -z "$Q_SCRIPT_DIR" ]]; then
Q_SCRIPT_DIR=~/.config/q.sh Q_SCRIPT_DIR=~/.config/q.sh
fi fi
SELF="$0" SELF=$(cd -P -- "$(dirname -- "$0")" && printf '%s\n' "$(pwd -P)/$(basename -- "$0")")
INDEX_FILE=~/.q.index INDEX_FILE=~/.q.index
HINT_FILE=~/.q.hints HINT_FILE=~/.q.hints
@ -198,7 +198,7 @@ if [[ -z "$COMMAND" ]]; then
PREF="$SELF -c" PREF="$SELF -c"
INITIAL="" INITIAL=""
FZF_DEFAULT_COMMAND="$PREF '$INITIAL'" fzf \ FZF_DEFAULT_COMMAND="$PREF '$INITIAL'" fzf \
--bind "change:reload:$PREF {q} || true" \ --bind "change:reload-sync:$PREF {q} || true" \
--ansi --query "$INITIAL" \ --ansi --query "$INITIAL" \
--preview "$SELF -p {}" \ --preview "$SELF -p {}" \
--with-nth="2..-1" \ --with-nth="2..-1" \

View file

@ -1,4 +1,4 @@
#!/bin/bash #!/bin/sh
if [[ -z "$@" ]]; then if [[ -z "$@" ]]; then

19
q-browse Executable file
View file

@ -0,0 +1,19 @@
#!/bin/sh
if [[ -z "$@" ]]; then
echo "^f .*$"
elif [[ "$1" == "--hint" ]]; then
shift
elif [[ "$1" == "--complete" ]]; then
shift
echo "0 $@"
elif [[ "$1" == "--preview" ]]; then
shift
URL="$(echo "$@" | cut -d ' ' -f3-)"
echo "Will open '$URL' in firefox"
elif [[ "$1" == "--run" ]]; then
shift
URL="$(echo "$@" | cut -d ' ' -f3-)"
(nohup xdg-open "$URL" 2>/dev/null &)
sleep 0.01
fi

2
q-calc
View file

@ -1,4 +1,4 @@
#!/bin/bash #!/bin/sh
calc() { calc() {
res="$(echo "$1" | bc 2>/dev/null)" res="$(echo "$1" | bc 2>/dev/null)"

View file

@ -1,4 +1,4 @@
#!/bin/bash #!/bin/sh
if [[ -z "$@" ]]; then if [[ -z "$@" ]]; then

2
q-pass
View file

@ -1,4 +1,4 @@
#!/bin/bash #!/bin/sh
if [[ -z "$@" ]]; then if [[ -z "$@" ]]; then
# Return a regular expression that should trigger # Return a regular expression that should trigger

26
q-run Executable file
View file

@ -0,0 +1,26 @@
#!/bin/sh
export PATH=~/.prefix/bin:~/.local/bin:$PATH
find_all_executables() {
{
IFS=:; for d in $PATH; do for f in $d/*; do [ -f $f ] && [ -x $f ] && echo ${f##*/}; done; done;
} | sort
#flatpak --columns=application --app list | tail -n +1 | awk '{print "flatpak run " $0}';
}
if [[ -z "$@" ]]; then
echo "^run [a-zA-Z0-9_-]*$"
elif [[ "$1" == "--hint" ]]; then
find_all_executables | awk '{print $1 " run " $1}'
elif [[ "$1" == "--complete" ]]; then
shift
find_all_executables | awk '{print $1 " run " $1}'
elif [[ "$1" == "--preview" ]]; then
shift
echo "Will run $1"
elif [[ "$1" == "--run" ]]; then
shift
(nohup "$1" 2>/dev/null &)
sleep 0.01
fi