mirror of
https://git.sr.ht/~coasteen/dotfiles
synced 2025-11-04 14:47:38 +01:00
suicide
This commit is contained in:
parent
7c844a39fc
commit
8511744c50
17 changed files with 1087 additions and 8905 deletions
|
|
@ -1,29 +0,0 @@
|
|||
background #202020
|
||||
foreground #d0d0d0
|
||||
cursor #d0d0d0
|
||||
selection_background #eecb8b
|
||||
color0 #151515
|
||||
color8 #505050
|
||||
color1 #ac4142
|
||||
color9 #ac4142
|
||||
color2 #7e8d50
|
||||
color10 #7e8d50
|
||||
color3 #e5b566
|
||||
color11 #e5b566
|
||||
color4 #6c99ba
|
||||
color12 #6c99ba
|
||||
color5 #9e4e85
|
||||
color13 #9e4e85
|
||||
color6 #7dd5cf
|
||||
color14 #7dd5cf
|
||||
color7 #d0d0d0
|
||||
color15 #f5f5f5
|
||||
selection_foreground #232323
|
||||
|
||||
# START_AUTOGENERATED_TAB_STYLE
|
||||
# Feel free to update these colors manually and remove these comments.
|
||||
active_tab_foreground #444444
|
||||
active_tab_background #eecb8b
|
||||
inactive_tab_foreground #d0d0d0
|
||||
inactive_tab_background #1a1a1a
|
||||
# END_AUTOGENERATED_TAB_STYLE
|
||||
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
|
@ -1,21 +0,0 @@
|
|||
background #121218
|
||||
foreground #cef3ff
|
||||
cursor #ffffff
|
||||
selection_background #44475a
|
||||
color0 #000000
|
||||
color8 #545454
|
||||
color1 #ff5555
|
||||
color9 #ff5454
|
||||
color2 #fa0074
|
||||
color10 #50fa7b
|
||||
color3 #7f0a1f
|
||||
color11 #f0fa8b
|
||||
color4 #3282ff
|
||||
color12 #1200f8
|
||||
color5 #1b3cff
|
||||
color13 #ff78c5
|
||||
color6 #0037fc
|
||||
color14 #8ae9fc
|
||||
color7 #bbbbbb
|
||||
color15 #ffffff
|
||||
selection_foreground #222330
|
||||
|
|
@ -1,41 +1,28 @@
|
|||
#exec waybar &
|
||||
#exec autotiling &
|
||||
#touchpad
|
||||
exec autotiling
|
||||
input "1267:12448:ELAN0709:00_04F3:30A0_Touchpad" {
|
||||
dwt enabled
|
||||
tap enabled
|
||||
middle_emulation enabled
|
||||
}
|
||||
|
||||
#cursor
|
||||
seat * xcursor_theme ModernXP 32
|
||||
|
||||
# gaps
|
||||
dwt enabled
|
||||
tap enabled
|
||||
middle_emulation enabled
|
||||
}
|
||||
|
||||
gaps inner 5
|
||||
gaps outer 2
|
||||
|
||||
### Variables
|
||||
#
|
||||
# Logo key. Use Mod1 for Alt.
|
||||
set $mod Mod4
|
||||
# Home row direction keys, like vim
|
||||
set $left h
|
||||
set $down j
|
||||
set $up k
|
||||
set $right l
|
||||
# Your preferred terminal emulator
|
||||
set $term kitty
|
||||
set $filemgr kitty -e ranger
|
||||
# Your preferred application launcher
|
||||
set $filemgr2 caja
|
||||
set $menu wmenu-run -f "UbuntuMono 15" -N "#1c1c1c" -n "#B0B0B0" -S "#2d2d2d" -s "#ffffff" -l 10
|
||||
# set browser
|
||||
set $browser brave
|
||||
|
||||
output eDP-1 disable
|
||||
#output eDP-1 pos 0 0
|
||||
output HDMI-A-1 pos 1920 0
|
||||
|
||||
output * bg /home/coast/Pictures/nature3.png stretch
|
||||
output * bg /home/coast/Pictures/painting1.png stretch
|
||||
output HDMI-A-1 resolution 1920x1080 position 1920,0
|
||||
|
||||
exec swayidle -w \
|
||||
|
|
@ -66,11 +53,6 @@ client.urgent #ff0000 #000000 #ffffff #ff0000 #ff0000
|
|||
|
||||
bindsym $mod+Shift+b exec $browser
|
||||
|
||||
# Drag floating windows by holding down $mod and left mouse button.
|
||||
# Resize them with right mouse button + $mod.
|
||||
# Despite the name, also works for non-floating windows.
|
||||
# Change normal to inverse to use left mouse button for resizing and right
|
||||
# mouse button for dragging.
|
||||
floating_modifier $mod normal
|
||||
|
||||
bindsym $mod+Shift+c reload
|
||||
|
|
@ -78,32 +60,25 @@ client.urgent #ff0000 #000000 #ffffff #ff0000 #ff0000
|
|||
bindsym $mod+Shift+q exec 'swaymsg exit'
|
||||
|
||||
bindsym $mod+Shift+f exec $filemgr
|
||||
#
|
||||
# Moving around:
|
||||
#
|
||||
# Move your focus around
|
||||
bindsym $mod+Shift+i exec $filemgr2
|
||||
bindsym $mod+$left focus left
|
||||
bindsym $mod+$down focus down
|
||||
bindsym $mod+$up focus up
|
||||
bindsym $mod+$right focus right
|
||||
# Or use $mod+[up|down|left|right]
|
||||
bindsym $mod+Left focus left
|
||||
bindsym $mod+Down focus down
|
||||
bindsym $mod+Up focus up
|
||||
bindsym $mod+Right focus right
|
||||
|
||||
# Move the focused window with the same, but add Shift
|
||||
bindsym $mod+Shift+$left move left
|
||||
bindsym $mod+Shift+$down move down
|
||||
bindsym $mod+Shift+$up move up
|
||||
bindsym $mod+Shift+$right move right
|
||||
# Ditto, with arrow keys
|
||||
bindsym $mod+Shift+Left move left
|
||||
bindsym $mod+Shift+Down move down
|
||||
bindsym $mod+Shift+Up move up
|
||||
bindsym $mod+Shift+Right move right
|
||||
|
||||
# Switch to workspace
|
||||
bindsym $mod+1 workspace number 1
|
||||
bindsym $mod+2 workspace number 2
|
||||
bindsym $mod+3 workspace number 3
|
||||
|
|
@ -114,7 +89,6 @@ client.urgent #ff0000 #000000 #ffffff #ff0000 #ff0000
|
|||
bindsym $mod+8 workspace number 8
|
||||
bindsym $mod+9 workspace number 9
|
||||
|
||||
# Move focused container to workspace
|
||||
bindsym $mod+Shift+1 move container to workspace number 1
|
||||
bindsym $mod+Shift+2 move container to workspace number 2
|
||||
bindsym $mod+Shift+3 move container to workspace number 3
|
||||
|
|
@ -125,91 +99,50 @@ client.urgent #ff0000 #000000 #ffffff #ff0000 #ff0000
|
|||
bindsym $mod+Shift+8 move container to workspace number 8
|
||||
bindsym $mod+Shift+9 move container to workspace number 9
|
||||
|
||||
# Note: workspaces can have any name you want, not just numbers.
|
||||
# We just use 1-10 as the default.
|
||||
#
|
||||
# Layout stuff:
|
||||
#
|
||||
# You can "split" the current object of your focus with
|
||||
# $mod+b or $mod+v, for horizontal and vertical splits
|
||||
# respectively.
|
||||
bindsym $mod+b splith
|
||||
bindsym $mod+v splitv
|
||||
|
||||
# Switch the current container between different layout styles
|
||||
bindsym $mod+Shift+s layout stacking
|
||||
bindsym $mod+Shift+w layout tabbed
|
||||
bindsym $mod+Shift+e layout toggle split
|
||||
|
||||
# Make the current focus fullscreen
|
||||
bindsym $mod+f fullscreen
|
||||
|
||||
bindsym Print exec 'hyprshot -m region -o /home/coast/Pictures/Screenshots/'
|
||||
bindsym Print exec /home/coast/.local/src/local/bin/screenie-wl
|
||||
|
||||
# Toggle the current focus between tiling and floating mode
|
||||
bindsym $mod+space floating toggle
|
||||
|
||||
# Swap focus between the tiling area and the floating area
|
||||
bindsym $mod+Shift+space focus mode_toggle
|
||||
|
||||
# Move focus to the parent container
|
||||
bindsym $mod+a focus parent
|
||||
|
||||
bindsym $mod+Shift+u exec 'pkill waybar; waybar &'
|
||||
#
|
||||
# Scratchpad:
|
||||
#
|
||||
# Sway has a "scratchpad", which is a bag of holding for windows.
|
||||
# You can send windows there and get them back later.
|
||||
|
||||
# Move the currently focused window to the scratchpad
|
||||
bindsym $mod+Shift+minus move scratchpad
|
||||
|
||||
# Show the next scratchpad window or hide the focused scratchpad window.
|
||||
# If there are multiple scratchpad windows, this command cycles through them.
|
||||
bindsym $mod+minus scratchpad show
|
||||
#
|
||||
# Resizing containers:
|
||||
#
|
||||
mode "resize" {
|
||||
# left will shrink the containers width
|
||||
# right will grow the containers width
|
||||
# up will shrink the containers height
|
||||
# down will grow the containers height
|
||||
bindsym $left resize shrink width 10px
|
||||
bindsym $down resize grow height 10px
|
||||
bindsym $up resize shrink height 10px
|
||||
bindsym $right resize grow width 10px
|
||||
|
||||
# Ditto, with arrow keys
|
||||
bindsym Right resize shrink width 10px
|
||||
bindsym Up resize grow height 10px
|
||||
bindsym Down resize shrink height 10px
|
||||
bindsym Left resize grow width 10px
|
||||
|
||||
# Return to default mode
|
||||
bindsym Return mode "default"
|
||||
bindsym Escape mode "default"
|
||||
}
|
||||
bindsym $mod+Shift+d mode "resize"
|
||||
|
||||
#
|
||||
# Utilities:
|
||||
#
|
||||
# Special keys to adjust volume via PulseAudio
|
||||
bindsym --locked XF86AudioMute exec pactl set-sink-mute \@DEFAULT_SINK@ toggle
|
||||
bindsym --locked XF86AudioLowerVolume exec pactl set-sink-volume \@DEFAULT_SINK@ -5%
|
||||
bindsym --locked XF86AudioRaiseVolume exec pactl set-sink-volume \@DEFAULT_SINK@ +5%
|
||||
bindsym --locked XF86AudioMicMute exec pactl set-source-mute \@DEFAULT_SOURCE@ toggle
|
||||
# Special keys to adjust brightness via brightnessctl
|
||||
bindsym --locked XF86MonBrightnessDown exec brightnessctl set 5%-
|
||||
bindsym --locked XF86MonBrightnessUp exec brightnessctl set 5%+
|
||||
# Special key to take a screenshot with grim
|
||||
|
||||
#
|
||||
# Status Bar:
|
||||
#
|
||||
# Read `man 5 sway-bar` for more information about this section.
|
||||
|
||||
bar {
|
||||
position top
|
||||
|
|
@ -231,4 +164,3 @@ bar {
|
|||
|
||||
include /etc/sway/config.d/*
|
||||
for_window [app_id="foot"] opacity 0.9
|
||||
|
||||
|
|
|
|||
|
|
@ -1,102 +1,73 @@
|
|||
{ config, pkgs, ... }:
|
||||
{
|
||||
{ config, lib, pkgs, ... }: let
|
||||
home-manager = builtins.fetchTarball "https://github.com/nix-community/home-manager/archive/release-25.05.tar.gz";
|
||||
in {
|
||||
imports =
|
||||
[
|
||||
./hardware-configuration.nix
|
||||
(import "${home-manager}/nixos")
|
||||
./zsh.nix
|
||||
./packages.nix
|
||||
];
|
||||
|
||||
boot.loader = {
|
||||
grub.enable = true;
|
||||
grub.efiSupport = true;
|
||||
grub.device = "nodev";
|
||||
systemd-boot.enable = false;
|
||||
efi.canTouchEfiVariables = true;
|
||||
};
|
||||
|
||||
boot.plymouth = {
|
||||
enable = true;
|
||||
theme = "blahaj";
|
||||
themePackages = [ pkgs.plymouth-blahaj-theme ];
|
||||
};
|
||||
home-manager.useUserPackages = true;
|
||||
home-manager.useGlobalPkgs = true;
|
||||
home-manager.backupFileExtension = "backup";
|
||||
home-manager.users.coast = import ./home.nix;
|
||||
|
||||
boot.kernelPackages = pkgs.linuxPackages_xanmod_latest;
|
||||
boot.loader.systemd-boot.enable = true;
|
||||
boot.loader.efi.canTouchEfiVariables = true;
|
||||
|
||||
networking.hostName = "core";
|
||||
networking.networkmanager.enable = true;
|
||||
networking.enableIPv6 = false;
|
||||
|
||||
time.timeZone = "Asia/Tehran";
|
||||
|
||||
i18n.defaultLocale = "en_US.UTF-8";
|
||||
|
||||
services.xserver.enable = true;
|
||||
services.displayManager.ly.enable = true;
|
||||
|
||||
services.xserver.xkb = {
|
||||
layout = "us";
|
||||
variant = "";
|
||||
};
|
||||
|
||||
services.jellyfin.enable = true;
|
||||
services.printing.enable = false;
|
||||
|
||||
services.pipewire = {
|
||||
enable = true;
|
||||
alsa.enable = true;
|
||||
pulse.enable = true;
|
||||
jack.enable = true;
|
||||
wireplumber.enable = true;
|
||||
};
|
||||
|
||||
services.libinput.enable = true;
|
||||
programs.nano.enable = false;
|
||||
security.sudo.enable = false;
|
||||
security.doas = {
|
||||
enable = true;
|
||||
extraRules = [{ users = [ "coast" ]; keepEnv = true; persist = true; }];
|
||||
};
|
||||
|
||||
programs.zsh.enable = true;
|
||||
programs.zsh.syntaxHighlighting.enable = true;
|
||||
|
||||
nixpkgs.config.allowUnfree = true;
|
||||
|
||||
users.users.coast = {
|
||||
isNormalUser = true;
|
||||
description = "coast";
|
||||
extraGroups = [ "networkmanager" "wheel" "video" "audio" ];
|
||||
extraGroups = [ "wheel" ];
|
||||
shell = pkgs.zsh;
|
||||
};
|
||||
|
||||
hardware.bluetooth.enable = true;
|
||||
hardware.bluetooth.powerOnBoot = true;
|
||||
services.blueman.enable = true;
|
||||
|
||||
services.flatpak.enable = true;
|
||||
services.jellyfin.enable = true;
|
||||
programs.steam.enable = true;
|
||||
programs.sway.enable = true;
|
||||
|
||||
hardware.graphics.enable = true;
|
||||
services.xserver.videoDrivers = ["nvidia"];
|
||||
hardware.nvidia = {
|
||||
modesetting.enable = true;
|
||||
powerManagement.enable = false;
|
||||
open = false;
|
||||
nvidiaSettings = true;
|
||||
package = config.boot.kernelPackages.nvidiaPackages.beta;
|
||||
security.sudo.enable = false;
|
||||
security.doas = {
|
||||
enable = true;
|
||||
extraRules = [{ users = [ "coast" ]; keepEnv = true; persist = true; }];
|
||||
};
|
||||
|
||||
boot.kernelParams = [ "nvidia_drm.modeset=0" ];
|
||||
boot.blacklistedKernelModules = [ "nouveau" ];
|
||||
|
||||
nixpkgs.config.allowUnfree = true;
|
||||
|
||||
environment.systemPackages = with pkgs; [
|
||||
pcmanfm wayland-utils
|
||||
wl-clipboard git
|
||||
neovim wget nekoray alsa-utils nerd-fonts.ubuntu
|
||||
(pkgs.runCommand "vim-wrapper" { } ''
|
||||
mkdir -p $out/bin
|
||||
ln -s ${pkgs.neovim}/bin/nvim $out/bin/vim
|
||||
'')
|
||||
neovim
|
||||
wget
|
||||
adwaita-icon-theme
|
||||
(pkgs.runCommand "vim-wrapper" { } ''
|
||||
mkdir -p $out/bin
|
||||
ln -s ${pkgs.neovim}/bin/nvim $out/bin/vim
|
||||
'')
|
||||
(import ./prism.nix { stdenv = pkgs.stdenv; })
|
||||
];
|
||||
|
||||
programs.zsh.enable = true;
|
||||
programs.zsh.syntaxHighlighting.enable = true;
|
||||
programs.foot.enable = false;
|
||||
programs.nekoray.enable = true;
|
||||
programs.nekoray.tunMode.enable = true;
|
||||
programs.nano.enable = false;
|
||||
programs.sway.enable = true;
|
||||
|
||||
fonts.packages = with pkgs; [
|
||||
ubuntu-sans
|
||||
ubuntu_font_family
|
||||
|
|
@ -104,22 +75,16 @@
|
|||
nerd-fonts.droid-sans-mono
|
||||
];
|
||||
|
||||
programs.nekoray = {
|
||||
enable = true;
|
||||
tunMode.enable = true;
|
||||
hardware.graphics.enable = true;
|
||||
services.xserver.videoDrivers = ["nvidia"];
|
||||
hardware.nvidia = {
|
||||
modesetting.enable = true;
|
||||
powerManagement.enable = false;
|
||||
open = false;
|
||||
nvidiaSettings = true;
|
||||
package = config.boot.kernelPackages.nvidiaPackages.stable;
|
||||
};
|
||||
|
||||
# Some programs need SUID wrappers, can be configured further or are
|
||||
# started in user sessions.
|
||||
# programs.mtr.enable = true;
|
||||
# programs.gnupg.agent = {
|
||||
# enable = true;
|
||||
# enableSSHSupport = true;
|
||||
# };
|
||||
|
||||
services.openssh.enable = true;
|
||||
networking.firewall.enable = false;
|
||||
nix.settings.experimental-features = [ "nix-command" "flakes" ];
|
||||
system.stateVersion = "25.05";
|
||||
|
||||
}
|
||||
|
|
|
|||
62
etc/nixos/flake.lock
generated
62
etc/nixos/flake.lock
generated
|
|
@ -1,62 +0,0 @@
|
|||
{
|
||||
"nodes": {
|
||||
"home-manager": {
|
||||
"inputs": {
|
||||
"nixpkgs": "nixpkgs"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1759172751,
|
||||
"narHash": "sha256-E8W8sRXfrvkFW26GuuiWq6QfReU7m5+cngwHuRo/3jc=",
|
||||
"owner": "nix-community",
|
||||
"repo": "home-manager",
|
||||
"rev": "12fa8548feefa9a10266ba65152fd1a787cdde8f",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-community",
|
||||
"repo": "home-manager",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1758690382,
|
||||
"narHash": "sha256-NY3kSorgqE5LMm1LqNwGne3ZLMF2/ILgLpFr1fS4X3o=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "e643668fd71b949c53f8626614b21ff71a07379d",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "nixos-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs_2": {
|
||||
"locked": {
|
||||
"lastModified": 1759036355,
|
||||
"narHash": "sha256-0m27AKv6ka+q270dw48KflE0LwQYrO7Fm4/2//KCVWg=",
|
||||
"owner": "nixos",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "e9f00bd893984bc8ce46c895c3bf7cac95331127",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nixos",
|
||||
"ref": "nixos-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"home-manager": "home-manager",
|
||||
"nixpkgs": "nixpkgs_2"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
{
|
||||
description = "Flake";
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
||||
home-manager.url = "github:nix-community/home-manager";
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, home-manager }: {
|
||||
nixosConfigurations.core = nixpkgs.lib.nixosSystem {
|
||||
system = "x86_64-linux";
|
||||
modules = [
|
||||
./configuration.nix
|
||||
./home.nix
|
||||
home-manager.nixosModules.home-manager
|
||||
];
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -1,275 +1,9 @@
|
|||
{ config, pkgs, ... }:
|
||||
|
||||
{
|
||||
home-manager.users.coast = {
|
||||
{ config, pkgs, ... }: {
|
||||
home.username = "coast";
|
||||
home.homeDirectory = "/home/coast";
|
||||
home.stateVersion = "25.05";
|
||||
|
||||
programs.vesktop.enable = true;
|
||||
|
||||
home.file.".config/qutebrowser/config.py".text = ''
|
||||
config.load_autoconfig()
|
||||
c.content.blocking.enabled = True
|
||||
config.set("content.geolocation", False)
|
||||
c.url.searchengines = {
|
||||
'DEFAULT': 'https://www.google.com/search?q={}',
|
||||
'ddg': 'https://duckduckgo.com/?q={}',
|
||||
'wiki': 'https://en.wikipedia.org/w/index.php?search={}',
|
||||
'gh': 'https://github.com/search?q={}',
|
||||
}
|
||||
c.url.start_pages = ['https://www.google.com']
|
||||
'';
|
||||
|
||||
home.packages = with pkgs; [
|
||||
zsh-autosuggestions
|
||||
blueman
|
||||
brave
|
||||
neofetch
|
||||
hyfetch
|
||||
nix-search-cli
|
||||
appimage-run
|
||||
krita
|
||||
python3
|
||||
hyprshot
|
||||
starship
|
||||
dysk
|
||||
ranger
|
||||
mako
|
||||
libnotify
|
||||
kitty
|
||||
mpv
|
||||
qbittorrent
|
||||
gcc
|
||||
ruby
|
||||
pciutils
|
||||
lm_sensors
|
||||
htop
|
||||
tealdeer
|
||||
];
|
||||
|
||||
home.file.".config/kitty/kitty.conf".text = ''
|
||||
font_family family="Ubuntu Mono"
|
||||
font_size 20
|
||||
bold_font auto
|
||||
italic_font auto
|
||||
bold_italic_font auto
|
||||
background_opacity 0.9
|
||||
window_padding_width 8
|
||||
confirm_os_window_close 0
|
||||
|
||||
background #1d1d1d
|
||||
foreground #deddda
|
||||
|
||||
selection_background #303030
|
||||
selection_foreground #c0bfbc
|
||||
|
||||
url_color #1a5fb4
|
||||
|
||||
wayland_titlebar_color system
|
||||
macos_titlebar_color system
|
||||
|
||||
cursor #deddda
|
||||
cursor_text_color #1d1d1d
|
||||
|
||||
active_border_color #4f4f4f
|
||||
inactive_border_color #282828
|
||||
bell_border_color #ed333b
|
||||
visual_bell_color none
|
||||
|
||||
active_tab_background #242424
|
||||
active_tab_foreground #fcfcfc
|
||||
inactive_tab_background #303030
|
||||
inactive_tab_foreground #b0afac
|
||||
tab_bar_background none
|
||||
tab_bar_margin_color none
|
||||
|
||||
color0 #1d1d1d
|
||||
color1 #ed333b
|
||||
color2 #57e389
|
||||
color3 #ff7800
|
||||
color4 #62a0ea
|
||||
color5 #9141ac
|
||||
color6 #5bc8af
|
||||
color7 #deddda
|
||||
|
||||
color8 #9a9996
|
||||
color9 #f66151
|
||||
color10 #8ff0a4
|
||||
color11 #ffa348
|
||||
color12 #99c1f1
|
||||
color13 #dc8add
|
||||
color14 #93ddc2
|
||||
color15 #f6f5f4
|
||||
'';
|
||||
|
||||
home.file.".config/sway/config".text = ''
|
||||
input "1267:12448:ELAN0709:00_04F3:30A0_Touchpad" {
|
||||
dwt enabled
|
||||
tap enabled
|
||||
middle_emulation enabled
|
||||
}
|
||||
|
||||
seat * xcursor_theme ModernXP 32
|
||||
|
||||
gaps inner 5
|
||||
gaps outer 2
|
||||
|
||||
set $mod Mod4
|
||||
set $left h
|
||||
set $down j
|
||||
set $up k
|
||||
set $right l
|
||||
set $term kitty
|
||||
set $filemgr kitty -e ranger
|
||||
set $menu wmenu-run -f "UbuntuMono 15" -N "#1c1c1c" -n "#B0B0B0" -S "#2d2d2d" -s "#ffffff" -l 10
|
||||
set $browser brave
|
||||
|
||||
output eDP-1 disable
|
||||
output HDMI-A-1 pos 1920 0
|
||||
|
||||
output * bg /home/coast/Pictures/nature3.png stretch
|
||||
output HDMI-A-1 resolution 1920x1080 position 1920,0
|
||||
|
||||
exec swayidle -w \
|
||||
timeout 300 'swaylock -f -c 000000' \
|
||||
timeout 600 'swaymsg "output * power off"' resume 'swaymsg "output * power on"' \
|
||||
before-sleep 'swaylock -f -c 000000'
|
||||
|
||||
input * {
|
||||
xkb_options caps:escape
|
||||
}
|
||||
|
||||
default_border pixel 4
|
||||
default_floating_border pixel 4
|
||||
|
||||
for_window [class=".*"] border pixel 4
|
||||
|
||||
client.focused #666666 #000000 #ffffff #666666 #666666
|
||||
client.unfocused #444444 #000000 #ffffff #444444 #444444
|
||||
client.focused_inactive #444444 #000000 #ffffff #444444 #444444
|
||||
client.urgent #ff0000 #000000 #ffffff #ff0000 #ff0000
|
||||
|
||||
|
||||
bindsym $mod+Return exec $term
|
||||
|
||||
bindsym $mod+s kill
|
||||
|
||||
bindsym $mod+r exec $menu
|
||||
|
||||
bindsym $mod+Shift+b exec $browser
|
||||
|
||||
floating_modifier $mod normal
|
||||
|
||||
bindsym $mod+Shift+c reload
|
||||
|
||||
bindsym $mod+Shift+q exec 'swaymsg exit'
|
||||
|
||||
bindsym $mod+Shift+f exec $filemgr
|
||||
bindsym $mod+$left focus left
|
||||
bindsym $mod+$down focus down
|
||||
bindsym $mod+$up focus up
|
||||
bindsym $mod+$right focus right
|
||||
bindsym $mod+Left focus left
|
||||
bindsym $mod+Down focus down
|
||||
bindsym $mod+Up focus up
|
||||
bindsym $mod+Right focus right
|
||||
|
||||
bindsym $mod+Shift+$left move left
|
||||
bindsym $mod+Shift+$down move down
|
||||
bindsym $mod+Shift+$up move up
|
||||
bindsym $mod+Shift+$right move right
|
||||
bindsym $mod+Shift+Left move left
|
||||
bindsym $mod+Shift+Down move down
|
||||
bindsym $mod+Shift+Up move up
|
||||
bindsym $mod+Shift+Right move right
|
||||
|
||||
bindsym $mod+1 workspace number 1
|
||||
bindsym $mod+2 workspace number 2
|
||||
bindsym $mod+3 workspace number 3
|
||||
bindsym $mod+4 workspace number 4
|
||||
bindsym $mod+5 workspace number 5
|
||||
bindsym $mod+6 workspace number 6
|
||||
bindsym $mod+7 workspace number 7
|
||||
bindsym $mod+8 workspace number 8
|
||||
bindsym $mod+9 workspace number 9
|
||||
|
||||
bindsym $mod+Shift+1 move container to workspace number 1
|
||||
bindsym $mod+Shift+2 move container to workspace number 2
|
||||
bindsym $mod+Shift+3 move container to workspace number 3
|
||||
bindsym $mod+Shift+4 move container to workspace number 4
|
||||
bindsym $mod+Shift+5 move container to workspace number 5
|
||||
bindsym $mod+Shift+6 move container to workspace number 6
|
||||
bindsym $mod+Shift+7 move container to workspace number 7
|
||||
bindsym $mod+Shift+8 move container to workspace number 8
|
||||
bindsym $mod+Shift+9 move container to workspace number 9
|
||||
|
||||
bindsym $mod+b splith
|
||||
bindsym $mod+v splitv
|
||||
|
||||
bindsym $mod+Shift+s layout stacking
|
||||
bindsym $mod+Shift+w layout tabbed
|
||||
bindsym $mod+Shift+e layout toggle split
|
||||
|
||||
bindsym $mod+f fullscreen
|
||||
|
||||
bindsym Print exec 'hyprshot -m region -o /home/coast/Pictures/Screenshots/'
|
||||
|
||||
bindsym $mod+space floating toggle
|
||||
|
||||
bindsym $mod+Shift+space focus mode_toggle
|
||||
|
||||
bindsym $mod+a focus parent
|
||||
|
||||
bindsym $mod+Shift+u exec 'pkill waybar; waybar &'
|
||||
|
||||
bindsym $mod+Shift+minus move scratchpad
|
||||
|
||||
bindsym $mod+minus scratchpad show
|
||||
mode "resize" {
|
||||
bindsym $left resize shrink width 10px
|
||||
bindsym $down resize grow height 10px
|
||||
bindsym $up resize shrink height 10px
|
||||
bindsym $right resize grow width 10px
|
||||
|
||||
bindsym Right resize shrink width 10px
|
||||
bindsym Up resize grow height 10px
|
||||
bindsym Down resize shrink height 10px
|
||||
bindsym Left resize grow width 10px
|
||||
|
||||
bindsym Return mode "default"
|
||||
bindsym Escape mode "default"
|
||||
}
|
||||
bindsym $mod+Shift+d mode "resize"
|
||||
|
||||
bindsym --locked XF86AudioMute exec pactl set-sink-mute \@DEFAULT_SINK@ toggle
|
||||
bindsym --locked XF86AudioLowerVolume exec pactl set-sink-volume \@DEFAULT_SINK@ -5%
|
||||
bindsym --locked XF86AudioRaiseVolume exec pactl set-sink-volume \@DEFAULT_SINK@ +5%
|
||||
bindsym --locked XF86AudioMicMute exec pactl set-source-mute \@DEFAULT_SOURCE@ toggle
|
||||
bindsym --locked XF86MonBrightnessDown exec brightnessctl set 5%-
|
||||
bindsym --locked XF86MonBrightnessUp exec brightnessctl set 5%+
|
||||
|
||||
bar {
|
||||
position top
|
||||
font pango:Ubuntu 12
|
||||
|
||||
status_command while date +'%I:%M %p'; do sleep 1; done
|
||||
status_command while $HOME/.local/bin/sway-status; do sleep 1; done
|
||||
|
||||
tray_output primary
|
||||
|
||||
colors {
|
||||
statusline #ffffff
|
||||
background #1c1c1c
|
||||
inactive_workspace #1c1c1c #1c1c1c #aaaaaa
|
||||
focused_workspace #2d2d2d #262626 #ffffff
|
||||
urgent_workspace #aa0000 #ff0000 #ffffff
|
||||
}
|
||||
}
|
||||
|
||||
include /etc/sway/config.d/*
|
||||
for_window [app_id="foot"] opacity 0.9
|
||||
'';
|
||||
};
|
||||
home.file.".config/sway/config".source = "/home/coast/.local/src/config/sway/config";
|
||||
home.file.".config/mako/config".source = "/home/coast/.local/src/config/mako/config";
|
||||
home.file.".config/kitty/kitty.conf".source = "/home/coast/.local/src/config/kitty/kitty.conf";
|
||||
}
|
||||
|
||||
|
|
|
|||
29
etc/nixos/packages.nix
Normal file
29
etc/nixos/packages.nix
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
{ config, pkgs, lib, ... }: {
|
||||
home-manager.users.coast = {
|
||||
home.packages = with pkgs; [
|
||||
tree
|
||||
nwg-look
|
||||
mate.caja
|
||||
htop
|
||||
alsa-utils
|
||||
wl-clipboard
|
||||
dysk
|
||||
ranger
|
||||
kitty
|
||||
nix-search-cli
|
||||
neofetch
|
||||
mako
|
||||
ruby_3_4
|
||||
gcc
|
||||
libnotify
|
||||
grim
|
||||
slurp
|
||||
git
|
||||
autotiling
|
||||
appimage-run
|
||||
];
|
||||
|
||||
programs.firefox.enable = true;
|
||||
programs.vesktop.enable = true;
|
||||
};
|
||||
}
|
||||
18
etc/nixos/prism.nix
Normal file
18
etc/nixos/prism.nix
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
{ stdenv }:
|
||||
|
||||
stdenv.mkDerivation rec {
|
||||
pname = "prismlauncher";
|
||||
version = "1.0";
|
||||
|
||||
src = null;
|
||||
unpackPhase = ":";
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cat > $out/bin/prismlauncher <<'EOF'
|
||||
#!/bin/sh
|
||||
appimage-run /home/coast/AppImages/PrismLauncher-Linux-x86_64.AppImage
|
||||
EOF
|
||||
chmod +x $out/bin/prismlauncher
|
||||
'';
|
||||
}
|
||||
52
etc/nixos/zsh.nix
Normal file
52
etc/nixos/zsh.nix
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
{ pkgs, ... }: {
|
||||
home-manager.users.coast = {
|
||||
programs.zsh = {
|
||||
enable = true;
|
||||
|
||||
history = {
|
||||
path = "/home/coast/.cache/zsh/history";
|
||||
size = 100000000;
|
||||
save = 100000000;
|
||||
append = true;
|
||||
};
|
||||
|
||||
enableCompletion = true;
|
||||
|
||||
shellAliases = {
|
||||
nf = "neofetch";
|
||||
nrs = "doas nixos-rebuild switch";
|
||||
emoji = "cat ~/.local/src/local/share/emoji | grep";
|
||||
ls = "ls --color=auto";
|
||||
smi = "nvidia-smi";
|
||||
battery = "sb-battery";
|
||||
weather = "curl wttr.in/masjedsoleyman";
|
||||
las = "ls";
|
||||
c = "clear";
|
||||
cear = "clear";
|
||||
".." = "cd ..";
|
||||
hotp = "htop";
|
||||
main = "man";
|
||||
mian = "man";
|
||||
mna = "man";
|
||||
dias = "doas";
|
||||
};
|
||||
|
||||
initContent = ''
|
||||
autoload -U compinit
|
||||
zstyle ':completion:*' menu select
|
||||
zmodload zsh/complist
|
||||
compinit
|
||||
comp_options+=(globdots)
|
||||
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}'
|
||||
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=12"
|
||||
autoload -U colors && colors && setopt prompt_subst
|
||||
PROMPT="[%n@%m %~]%% "
|
||||
export LIBCLANG_PATH=/usr/lib/llvm/20/lib64
|
||||
export PATH=$PATH:/home/coast/.spicetify
|
||||
source ~/.local/src/zsh.d/zsh-autosuggestions.zsh
|
||||
export PATH="/usr/bin:$PATH"
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -1,16 +1,19 @@
|
|||
#!/usr/bin/env python3
|
||||
import subprocess, datetime, os
|
||||
#!/usr/bin/env zsh
|
||||
|
||||
d = os.path.expanduser("~/files/pics/screenies")
|
||||
os.makedirs(d, exist_ok=True)
|
||||
f = f"screenshot_{datetime.datetime.now():%Y-%m-%d_%H-%M-%S}.png"
|
||||
p = os.path.join(d, f)
|
||||
DIR=~/Pictures/Screenshots
|
||||
mkdir -p "$DIR"
|
||||
|
||||
r = subprocess.run(["slurp"], capture_output=True, text=True)
|
||||
if r.returncode: exit(1)
|
||||
TIMESTAMP=$(date +"%Y-%m-%d_%H-%M-%S")
|
||||
FILENAME="screenshot_${TIMESTAMP}.png"
|
||||
FILEPATH="${DIR}/${FILENAME}"
|
||||
|
||||
subprocess.run(["grim", "-g", r.stdout.strip(), p])
|
||||
with open(p, "rb") as image_file:
|
||||
subprocess.run(["wl-copy"], stdin=image_file)
|
||||
subprocess.run(["notify-send", "Screenshot saved", p])
|
||||
print(p)
|
||||
REGION=$(slurp)
|
||||
if [[ -z "$REGION" ]]; then
|
||||
notify-send "Screenshot canceled" "No region selected"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
grim -g "$REGION" "$FILEPATH"
|
||||
wl-copy < "$FILEPATH"
|
||||
notify-send "Screenshot saved" "$FILEPATH"
|
||||
echo "$FILEPATH"
|
||||
|
|
|
|||
BIN
wall/painting1.png
Normal file
BIN
wall/painting1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.9 MiB |
BIN
wall/painting2.png
Normal file
BIN
wall/painting2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.1 MiB |
867
zsh.d/zsh-autosuggestions.zsh
Normal file
867
zsh.d/zsh-autosuggestions.zsh
Normal file
|
|
@ -0,0 +1,867 @@
|
|||
# Fish-like fast/unobtrusive autosuggestions for zsh.
|
||||
# https://github.com/zsh-users/zsh-autosuggestions
|
||||
# v0.7.1
|
||||
# Copyright (c) 2013 Thiago de Arruda
|
||||
# Copyright (c) 2016-2021 Eric Freese
|
||||
#
|
||||
# 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.
|
||||
|
||||
#--------------------------------------------------------------------#
|
||||
# Global Configuration Variables #
|
||||
#--------------------------------------------------------------------#
|
||||
|
||||
# Color to use when highlighting suggestion
|
||||
# Uses format of `region_highlight`
|
||||
# More info: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Zle-Widgets
|
||||
(( ! ${+ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE} )) &&
|
||||
typeset -g ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=8'
|
||||
|
||||
# Prefix to use when saving original versions of bound widgets
|
||||
(( ! ${+ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX} )) &&
|
||||
typeset -g ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX=autosuggest-orig-
|
||||
|
||||
# Strategies to use to fetch a suggestion
|
||||
# Will try each strategy in order until a suggestion is returned
|
||||
(( ! ${+ZSH_AUTOSUGGEST_STRATEGY} )) && {
|
||||
typeset -ga ZSH_AUTOSUGGEST_STRATEGY
|
||||
ZSH_AUTOSUGGEST_STRATEGY=(history)
|
||||
}
|
||||
|
||||
# Widgets that clear the suggestion
|
||||
(( ! ${+ZSH_AUTOSUGGEST_CLEAR_WIDGETS} )) && {
|
||||
typeset -ga ZSH_AUTOSUGGEST_CLEAR_WIDGETS
|
||||
ZSH_AUTOSUGGEST_CLEAR_WIDGETS=(
|
||||
history-search-forward
|
||||
history-search-backward
|
||||
history-beginning-search-forward
|
||||
history-beginning-search-backward
|
||||
history-beginning-search-forward-end
|
||||
history-beginning-search-backward-end
|
||||
history-substring-search-up
|
||||
history-substring-search-down
|
||||
up-line-or-beginning-search
|
||||
down-line-or-beginning-search
|
||||
up-line-or-history
|
||||
down-line-or-history
|
||||
accept-line
|
||||
copy-earlier-word
|
||||
)
|
||||
}
|
||||
|
||||
# Widgets that accept the entire suggestion
|
||||
(( ! ${+ZSH_AUTOSUGGEST_ACCEPT_WIDGETS} )) && {
|
||||
typeset -ga ZSH_AUTOSUGGEST_ACCEPT_WIDGETS
|
||||
ZSH_AUTOSUGGEST_ACCEPT_WIDGETS=(
|
||||
forward-char
|
||||
end-of-line
|
||||
vi-forward-char
|
||||
vi-end-of-line
|
||||
vi-add-eol
|
||||
)
|
||||
}
|
||||
|
||||
# Widgets that accept the entire suggestion and execute it
|
||||
(( ! ${+ZSH_AUTOSUGGEST_EXECUTE_WIDGETS} )) && {
|
||||
typeset -ga ZSH_AUTOSUGGEST_EXECUTE_WIDGETS
|
||||
ZSH_AUTOSUGGEST_EXECUTE_WIDGETS=(
|
||||
)
|
||||
}
|
||||
|
||||
# Widgets that accept the suggestion as far as the cursor moves
|
||||
(( ! ${+ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS} )) && {
|
||||
typeset -ga ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS
|
||||
ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS=(
|
||||
forward-word
|
||||
emacs-forward-word
|
||||
vi-forward-word
|
||||
vi-forward-word-end
|
||||
vi-forward-blank-word
|
||||
vi-forward-blank-word-end
|
||||
vi-find-next-char
|
||||
vi-find-next-char-skip
|
||||
)
|
||||
}
|
||||
|
||||
# Widgets that should be ignored (globbing supported but must be escaped)
|
||||
(( ! ${+ZSH_AUTOSUGGEST_IGNORE_WIDGETS} )) && {
|
||||
typeset -ga ZSH_AUTOSUGGEST_IGNORE_WIDGETS
|
||||
ZSH_AUTOSUGGEST_IGNORE_WIDGETS=(
|
||||
orig-\*
|
||||
beep
|
||||
run-help
|
||||
set-local-history
|
||||
which-command
|
||||
yank
|
||||
yank-pop
|
||||
zle-\*
|
||||
)
|
||||
}
|
||||
|
||||
# Pty name for capturing completions for completion suggestion strategy
|
||||
(( ! ${+ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME} )) &&
|
||||
typeset -g ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME=zsh_autosuggest_completion_pty
|
||||
|
||||
#--------------------------------------------------------------------#
|
||||
# Utility Functions #
|
||||
#--------------------------------------------------------------------#
|
||||
|
||||
_zsh_autosuggest_escape_command() {
|
||||
setopt localoptions EXTENDED_GLOB
|
||||
|
||||
# Escape special chars in the string (requires EXTENDED_GLOB)
|
||||
echo -E "${1//(#m)[\"\'\\()\[\]|*?~]/\\$MATCH}"
|
||||
}
|
||||
|
||||
#--------------------------------------------------------------------#
|
||||
# Widget Helpers #
|
||||
#--------------------------------------------------------------------#
|
||||
|
||||
_zsh_autosuggest_incr_bind_count() {
|
||||
typeset -gi bind_count=$((_ZSH_AUTOSUGGEST_BIND_COUNTS[$1]+1))
|
||||
_ZSH_AUTOSUGGEST_BIND_COUNTS[$1]=$bind_count
|
||||
}
|
||||
|
||||
# Bind a single widget to an autosuggest widget, saving a reference to the original widget
|
||||
_zsh_autosuggest_bind_widget() {
|
||||
typeset -gA _ZSH_AUTOSUGGEST_BIND_COUNTS
|
||||
|
||||
local widget=$1
|
||||
local autosuggest_action=$2
|
||||
local prefix=$ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX
|
||||
|
||||
local -i bind_count
|
||||
|
||||
# Save a reference to the original widget
|
||||
case $widgets[$widget] in
|
||||
# Already bound
|
||||
user:_zsh_autosuggest_(bound|orig)_*)
|
||||
bind_count=$((_ZSH_AUTOSUGGEST_BIND_COUNTS[$widget]))
|
||||
;;
|
||||
|
||||
# User-defined widget
|
||||
user:*)
|
||||
_zsh_autosuggest_incr_bind_count $widget
|
||||
zle -N $prefix$bind_count-$widget ${widgets[$widget]#*:}
|
||||
;;
|
||||
|
||||
# Built-in widget
|
||||
builtin)
|
||||
_zsh_autosuggest_incr_bind_count $widget
|
||||
eval "_zsh_autosuggest_orig_${(q)widget}() { zle .${(q)widget} }"
|
||||
zle -N $prefix$bind_count-$widget _zsh_autosuggest_orig_$widget
|
||||
;;
|
||||
|
||||
# Completion widget
|
||||
completion:*)
|
||||
_zsh_autosuggest_incr_bind_count $widget
|
||||
eval "zle -C $prefix$bind_count-${(q)widget} ${${(s.:.)widgets[$widget]}[2,3]}"
|
||||
;;
|
||||
esac
|
||||
|
||||
# Pass the original widget's name explicitly into the autosuggest
|
||||
# function. Use this passed in widget name to call the original
|
||||
# widget instead of relying on the $WIDGET variable being set
|
||||
# correctly. $WIDGET cannot be trusted because other plugins call
|
||||
# zle without the `-w` flag (e.g. `zle self-insert` instead of
|
||||
# `zle self-insert -w`).
|
||||
eval "_zsh_autosuggest_bound_${bind_count}_${(q)widget}() {
|
||||
_zsh_autosuggest_widget_$autosuggest_action $prefix$bind_count-${(q)widget} \$@
|
||||
}"
|
||||
|
||||
# Create the bound widget
|
||||
zle -N -- $widget _zsh_autosuggest_bound_${bind_count}_$widget
|
||||
}
|
||||
|
||||
# Map all configured widgets to the right autosuggest widgets
|
||||
_zsh_autosuggest_bind_widgets() {
|
||||
emulate -L zsh
|
||||
|
||||
local widget
|
||||
local ignore_widgets
|
||||
|
||||
ignore_widgets=(
|
||||
.\*
|
||||
_\*
|
||||
${_ZSH_AUTOSUGGEST_BUILTIN_ACTIONS/#/autosuggest-}
|
||||
$ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX\*
|
||||
$ZSH_AUTOSUGGEST_IGNORE_WIDGETS
|
||||
)
|
||||
|
||||
# Find every widget we might want to bind and bind it appropriately
|
||||
for widget in ${${(f)"$(builtin zle -la)"}:#${(j:|:)~ignore_widgets}}; do
|
||||
if [[ -n ${ZSH_AUTOSUGGEST_CLEAR_WIDGETS[(r)$widget]} ]]; then
|
||||
_zsh_autosuggest_bind_widget $widget clear
|
||||
elif [[ -n ${ZSH_AUTOSUGGEST_ACCEPT_WIDGETS[(r)$widget]} ]]; then
|
||||
_zsh_autosuggest_bind_widget $widget accept
|
||||
elif [[ -n ${ZSH_AUTOSUGGEST_EXECUTE_WIDGETS[(r)$widget]} ]]; then
|
||||
_zsh_autosuggest_bind_widget $widget execute
|
||||
elif [[ -n ${ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS[(r)$widget]} ]]; then
|
||||
_zsh_autosuggest_bind_widget $widget partial_accept
|
||||
else
|
||||
# Assume any unspecified widget might modify the buffer
|
||||
_zsh_autosuggest_bind_widget $widget modify
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# Given the name of an original widget and args, invoke it, if it exists
|
||||
_zsh_autosuggest_invoke_original_widget() {
|
||||
# Do nothing unless called with at least one arg
|
||||
(( $# )) || return 0
|
||||
|
||||
local original_widget_name="$1"
|
||||
|
||||
shift
|
||||
|
||||
if (( ${+widgets[$original_widget_name]} )); then
|
||||
zle $original_widget_name -- $@
|
||||
fi
|
||||
}
|
||||
|
||||
#--------------------------------------------------------------------#
|
||||
# Highlighting #
|
||||
#--------------------------------------------------------------------#
|
||||
|
||||
# If there was a highlight, remove it
|
||||
_zsh_autosuggest_highlight_reset() {
|
||||
typeset -g _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT
|
||||
|
||||
if [[ -n "$_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT" ]]; then
|
||||
region_highlight=("${(@)region_highlight:#$_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT}")
|
||||
unset _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT
|
||||
fi
|
||||
}
|
||||
|
||||
# If there's a suggestion, highlight it
|
||||
_zsh_autosuggest_highlight_apply() {
|
||||
typeset -g _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT
|
||||
|
||||
if (( $#POSTDISPLAY )); then
|
||||
typeset -g _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT="$#BUFFER $(($#BUFFER + $#POSTDISPLAY)) $ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE"
|
||||
region_highlight+=("$_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT")
|
||||
else
|
||||
unset _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT
|
||||
fi
|
||||
}
|
||||
|
||||
#--------------------------------------------------------------------#
|
||||
# Autosuggest Widget Implementations #
|
||||
#--------------------------------------------------------------------#
|
||||
|
||||
# Disable suggestions
|
||||
_zsh_autosuggest_disable() {
|
||||
typeset -g _ZSH_AUTOSUGGEST_DISABLED
|
||||
_zsh_autosuggest_clear
|
||||
}
|
||||
|
||||
# Enable suggestions
|
||||
_zsh_autosuggest_enable() {
|
||||
unset _ZSH_AUTOSUGGEST_DISABLED
|
||||
|
||||
if (( $#BUFFER )); then
|
||||
_zsh_autosuggest_fetch
|
||||
fi
|
||||
}
|
||||
|
||||
# Toggle suggestions (enable/disable)
|
||||
_zsh_autosuggest_toggle() {
|
||||
if (( ${+_ZSH_AUTOSUGGEST_DISABLED} )); then
|
||||
_zsh_autosuggest_enable
|
||||
else
|
||||
_zsh_autosuggest_disable
|
||||
fi
|
||||
}
|
||||
|
||||
# Clear the suggestion
|
||||
_zsh_autosuggest_clear() {
|
||||
# Remove the suggestion
|
||||
POSTDISPLAY=
|
||||
|
||||
_zsh_autosuggest_invoke_original_widget $@
|
||||
}
|
||||
|
||||
# Modify the buffer and get a new suggestion
|
||||
_zsh_autosuggest_modify() {
|
||||
local -i retval
|
||||
|
||||
# Only available in zsh >= 5.4
|
||||
local -i KEYS_QUEUED_COUNT
|
||||
|
||||
# Save the contents of the buffer/postdisplay
|
||||
local orig_buffer="$BUFFER"
|
||||
local orig_postdisplay="$POSTDISPLAY"
|
||||
|
||||
# Clear suggestion while waiting for next one
|
||||
POSTDISPLAY=
|
||||
|
||||
# Original widget may modify the buffer
|
||||
_zsh_autosuggest_invoke_original_widget $@
|
||||
retval=$?
|
||||
|
||||
emulate -L zsh
|
||||
|
||||
# Don't fetch a new suggestion if there's more input to be read immediately
|
||||
if (( $PENDING > 0 || $KEYS_QUEUED_COUNT > 0 )); then
|
||||
POSTDISPLAY="$orig_postdisplay"
|
||||
return $retval
|
||||
fi
|
||||
|
||||
# Optimize if manually typing in the suggestion or if buffer hasn't changed
|
||||
if [[ "$BUFFER" = "$orig_buffer"* && "$orig_postdisplay" = "${BUFFER:$#orig_buffer}"* ]]; then
|
||||
POSTDISPLAY="${orig_postdisplay:$(($#BUFFER - $#orig_buffer))}"
|
||||
return $retval
|
||||
fi
|
||||
|
||||
# Bail out if suggestions are disabled
|
||||
if (( ${+_ZSH_AUTOSUGGEST_DISABLED} )); then
|
||||
return $?
|
||||
fi
|
||||
|
||||
# Get a new suggestion if the buffer is not empty after modification
|
||||
if (( $#BUFFER > 0 )); then
|
||||
if [[ -z "$ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE" ]] || (( $#BUFFER <= $ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE )); then
|
||||
_zsh_autosuggest_fetch
|
||||
fi
|
||||
fi
|
||||
|
||||
return $retval
|
||||
}
|
||||
|
||||
# Fetch a new suggestion based on what's currently in the buffer
|
||||
_zsh_autosuggest_fetch() {
|
||||
if (( ${+ZSH_AUTOSUGGEST_USE_ASYNC} )); then
|
||||
_zsh_autosuggest_async_request "$BUFFER"
|
||||
else
|
||||
local suggestion
|
||||
_zsh_autosuggest_fetch_suggestion "$BUFFER"
|
||||
_zsh_autosuggest_suggest "$suggestion"
|
||||
fi
|
||||
}
|
||||
|
||||
# Offer a suggestion
|
||||
_zsh_autosuggest_suggest() {
|
||||
emulate -L zsh
|
||||
|
||||
local suggestion="$1"
|
||||
|
||||
if [[ -n "$suggestion" ]] && (( $#BUFFER )); then
|
||||
POSTDISPLAY="${suggestion#$BUFFER}"
|
||||
else
|
||||
POSTDISPLAY=
|
||||
fi
|
||||
}
|
||||
|
||||
# Accept the entire suggestion
|
||||
_zsh_autosuggest_accept() {
|
||||
local -i retval max_cursor_pos=$#BUFFER
|
||||
|
||||
# When vicmd keymap is active, the cursor can't move all the way
|
||||
# to the end of the buffer
|
||||
if [[ "$KEYMAP" = "vicmd" ]]; then
|
||||
max_cursor_pos=$((max_cursor_pos - 1))
|
||||
fi
|
||||
|
||||
# If we're not in a valid state to accept a suggestion, just run the
|
||||
# original widget and bail out
|
||||
if (( $CURSOR != $max_cursor_pos || !$#POSTDISPLAY )); then
|
||||
_zsh_autosuggest_invoke_original_widget $@
|
||||
return
|
||||
fi
|
||||
|
||||
# Only accept if the cursor is at the end of the buffer
|
||||
# Add the suggestion to the buffer
|
||||
BUFFER="$BUFFER$POSTDISPLAY"
|
||||
|
||||
# Remove the suggestion
|
||||
POSTDISPLAY=
|
||||
|
||||
# Run the original widget before manually moving the cursor so that the
|
||||
# cursor movement doesn't make the widget do something unexpected
|
||||
_zsh_autosuggest_invoke_original_widget $@
|
||||
retval=$?
|
||||
|
||||
# Move the cursor to the end of the buffer
|
||||
if [[ "$KEYMAP" = "vicmd" ]]; then
|
||||
CURSOR=$(($#BUFFER - 1))
|
||||
else
|
||||
CURSOR=$#BUFFER
|
||||
fi
|
||||
|
||||
return $retval
|
||||
}
|
||||
|
||||
# Accept the entire suggestion and execute it
|
||||
_zsh_autosuggest_execute() {
|
||||
# Add the suggestion to the buffer
|
||||
BUFFER="$BUFFER$POSTDISPLAY"
|
||||
|
||||
# Remove the suggestion
|
||||
POSTDISPLAY=
|
||||
|
||||
# Call the original `accept-line` to handle syntax highlighting or
|
||||
# other potential custom behavior
|
||||
_zsh_autosuggest_invoke_original_widget "accept-line"
|
||||
}
|
||||
|
||||
# Partially accept the suggestion
|
||||
_zsh_autosuggest_partial_accept() {
|
||||
local -i retval cursor_loc
|
||||
|
||||
# Save the contents of the buffer so we can restore later if needed
|
||||
local original_buffer="$BUFFER"
|
||||
|
||||
# Temporarily accept the suggestion.
|
||||
BUFFER="$BUFFER$POSTDISPLAY"
|
||||
|
||||
# Original widget moves the cursor
|
||||
_zsh_autosuggest_invoke_original_widget $@
|
||||
retval=$?
|
||||
|
||||
# Normalize cursor location across vi/emacs modes
|
||||
cursor_loc=$CURSOR
|
||||
if [[ "$KEYMAP" = "vicmd" ]]; then
|
||||
cursor_loc=$((cursor_loc + 1))
|
||||
fi
|
||||
|
||||
# If we've moved past the end of the original buffer
|
||||
if (( $cursor_loc > $#original_buffer )); then
|
||||
# Set POSTDISPLAY to text right of the cursor
|
||||
POSTDISPLAY="${BUFFER[$(($cursor_loc + 1)),$#BUFFER]}"
|
||||
|
||||
# Clip the buffer at the cursor
|
||||
BUFFER="${BUFFER[1,$cursor_loc]}"
|
||||
else
|
||||
# Restore the original buffer
|
||||
BUFFER="$original_buffer"
|
||||
fi
|
||||
|
||||
return $retval
|
||||
}
|
||||
|
||||
() {
|
||||
typeset -ga _ZSH_AUTOSUGGEST_BUILTIN_ACTIONS
|
||||
|
||||
_ZSH_AUTOSUGGEST_BUILTIN_ACTIONS=(
|
||||
clear
|
||||
fetch
|
||||
suggest
|
||||
accept
|
||||
execute
|
||||
enable
|
||||
disable
|
||||
toggle
|
||||
)
|
||||
|
||||
local action
|
||||
for action in $_ZSH_AUTOSUGGEST_BUILTIN_ACTIONS modify partial_accept; do
|
||||
eval "_zsh_autosuggest_widget_$action() {
|
||||
local -i retval
|
||||
|
||||
_zsh_autosuggest_highlight_reset
|
||||
|
||||
_zsh_autosuggest_$action \$@
|
||||
retval=\$?
|
||||
|
||||
_zsh_autosuggest_highlight_apply
|
||||
|
||||
zle -R
|
||||
|
||||
return \$retval
|
||||
}"
|
||||
done
|
||||
|
||||
for action in $_ZSH_AUTOSUGGEST_BUILTIN_ACTIONS; do
|
||||
zle -N autosuggest-$action _zsh_autosuggest_widget_$action
|
||||
done
|
||||
}
|
||||
|
||||
#--------------------------------------------------------------------#
|
||||
# Completion Suggestion Strategy #
|
||||
#--------------------------------------------------------------------#
|
||||
# Fetches a suggestion from the completion engine
|
||||
#
|
||||
|
||||
_zsh_autosuggest_capture_postcompletion() {
|
||||
# Always insert the first completion into the buffer
|
||||
compstate[insert]=1
|
||||
|
||||
# Don't list completions
|
||||
unset 'compstate[list]'
|
||||
}
|
||||
|
||||
_zsh_autosuggest_capture_completion_widget() {
|
||||
# Add a post-completion hook to be called after all completions have been
|
||||
# gathered. The hook can modify compstate to affect what is done with the
|
||||
# gathered completions.
|
||||
local -a +h comppostfuncs
|
||||
comppostfuncs=(_zsh_autosuggest_capture_postcompletion)
|
||||
|
||||
# Only capture completions at the end of the buffer
|
||||
CURSOR=$#BUFFER
|
||||
|
||||
# Run the original widget wrapping `.complete-word` so we don't
|
||||
# recursively try to fetch suggestions, since our pty is forked
|
||||
# after autosuggestions is initialized.
|
||||
zle -- ${(k)widgets[(r)completion:.complete-word:_main_complete]}
|
||||
|
||||
if is-at-least 5.0.3; then
|
||||
# Don't do any cr/lf transformations. We need to do this immediately before
|
||||
# output because if we do it in setup, onlcr will be re-enabled when we enter
|
||||
# vared in the async code path. There is a bug in zpty module in older versions
|
||||
# where the tty is not properly attached to the pty slave, resulting in stty
|
||||
# getting stopped with a SIGTTOU. See zsh-workers thread 31660 and upstream
|
||||
# commit f75904a38
|
||||
stty -onlcr -ocrnl -F /dev/tty
|
||||
fi
|
||||
|
||||
# The completion has been added, print the buffer as the suggestion
|
||||
echo -nE - $'\0'$BUFFER$'\0'
|
||||
}
|
||||
|
||||
zle -N autosuggest-capture-completion _zsh_autosuggest_capture_completion_widget
|
||||
|
||||
_zsh_autosuggest_capture_setup() {
|
||||
# There is a bug in zpty module in older zsh versions by which a
|
||||
# zpty that exits will kill all zpty processes that were forked
|
||||
# before it. Here we set up a zsh exit hook to SIGKILL the zpty
|
||||
# process immediately, before it has a chance to kill any other
|
||||
# zpty processes.
|
||||
if ! is-at-least 5.4; then
|
||||
zshexit() {
|
||||
# The zsh builtin `kill` fails sometimes in older versions
|
||||
# https://unix.stackexchange.com/a/477647/156673
|
||||
kill -KILL $$ 2>&- || command kill -KILL $$
|
||||
|
||||
# Block for long enough for the signal to come through
|
||||
sleep 1
|
||||
}
|
||||
fi
|
||||
|
||||
# Try to avoid any suggestions that wouldn't match the prefix
|
||||
zstyle ':completion:*' matcher-list ''
|
||||
zstyle ':completion:*' path-completion false
|
||||
zstyle ':completion:*' max-errors 0 not-numeric
|
||||
|
||||
bindkey '^I' autosuggest-capture-completion
|
||||
}
|
||||
|
||||
_zsh_autosuggest_capture_completion_sync() {
|
||||
_zsh_autosuggest_capture_setup
|
||||
|
||||
zle autosuggest-capture-completion
|
||||
}
|
||||
|
||||
_zsh_autosuggest_capture_completion_async() {
|
||||
_zsh_autosuggest_capture_setup
|
||||
|
||||
zmodload zsh/parameter 2>/dev/null || return # For `$functions`
|
||||
|
||||
# Make vared completion work as if for a normal command line
|
||||
# https://stackoverflow.com/a/7057118/154703
|
||||
autoload +X _complete
|
||||
functions[_original_complete]=$functions[_complete]
|
||||
function _complete() {
|
||||
unset 'compstate[vared]'
|
||||
_original_complete "$@"
|
||||
}
|
||||
|
||||
# Open zle with buffer set so we can capture completions for it
|
||||
vared 1
|
||||
}
|
||||
|
||||
_zsh_autosuggest_strategy_completion() {
|
||||
# Reset options to defaults and enable LOCAL_OPTIONS
|
||||
emulate -L zsh
|
||||
|
||||
# Enable extended glob for completion ignore pattern
|
||||
setopt EXTENDED_GLOB
|
||||
|
||||
typeset -g suggestion
|
||||
local line REPLY
|
||||
|
||||
# Exit if we don't have completions
|
||||
whence compdef >/dev/null || return
|
||||
|
||||
# Exit if we don't have zpty
|
||||
zmodload zsh/zpty 2>/dev/null || return
|
||||
|
||||
# Exit if our search string matches the ignore pattern
|
||||
[[ -n "$ZSH_AUTOSUGGEST_COMPLETION_IGNORE" ]] && [[ "$1" == $~ZSH_AUTOSUGGEST_COMPLETION_IGNORE ]] && return
|
||||
|
||||
# Zle will be inactive if we are in async mode
|
||||
if zle; then
|
||||
zpty $ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME _zsh_autosuggest_capture_completion_sync
|
||||
else
|
||||
zpty $ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME _zsh_autosuggest_capture_completion_async "\$1"
|
||||
zpty -w $ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME $'\t'
|
||||
fi
|
||||
|
||||
{
|
||||
# The completion result is surrounded by null bytes, so read the
|
||||
# content between the first two null bytes.
|
||||
zpty -r $ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME line '*'$'\0''*'$'\0'
|
||||
|
||||
# Extract the suggestion from between the null bytes. On older
|
||||
# versions of zsh (older than 5.3), we sometimes get extra bytes after
|
||||
# the second null byte, so trim those off the end.
|
||||
# See http://www.zsh.org/mla/workers/2015/msg03290.html
|
||||
suggestion="${${(@0)line}[2]}"
|
||||
} always {
|
||||
# Destroy the pty
|
||||
zpty -d $ZSH_AUTOSUGGEST_COMPLETIONS_PTY_NAME
|
||||
}
|
||||
}
|
||||
|
||||
#--------------------------------------------------------------------#
|
||||
# History Suggestion Strategy #
|
||||
#--------------------------------------------------------------------#
|
||||
# Suggests the most recent history item that matches the given
|
||||
# prefix.
|
||||
#
|
||||
|
||||
_zsh_autosuggest_strategy_history() {
|
||||
# Reset options to defaults and enable LOCAL_OPTIONS
|
||||
emulate -L zsh
|
||||
|
||||
# Enable globbing flags so that we can use (#m) and (x~y) glob operator
|
||||
setopt EXTENDED_GLOB
|
||||
|
||||
# Escape backslashes and all of the glob operators so we can use
|
||||
# this string as a pattern to search the $history associative array.
|
||||
# - (#m) globbing flag enables setting references for match data
|
||||
# TODO: Use (b) flag when we can drop support for zsh older than v5.0.8
|
||||
local prefix="${1//(#m)[\\*?[\]<>()|^~#]/\\$MATCH}"
|
||||
|
||||
# Get the history items that match the prefix, excluding those that match
|
||||
# the ignore pattern
|
||||
local pattern="$prefix*"
|
||||
if [[ -n $ZSH_AUTOSUGGEST_HISTORY_IGNORE ]]; then
|
||||
pattern="($pattern)~($ZSH_AUTOSUGGEST_HISTORY_IGNORE)"
|
||||
fi
|
||||
|
||||
# Give the first history item matching the pattern as the suggestion
|
||||
# - (r) subscript flag makes the pattern match on values
|
||||
typeset -g suggestion="${history[(r)$pattern]}"
|
||||
}
|
||||
|
||||
#--------------------------------------------------------------------#
|
||||
# Match Previous Command Suggestion Strategy #
|
||||
#--------------------------------------------------------------------#
|
||||
# Suggests the most recent history item that matches the given
|
||||
# prefix and whose preceding history item also matches the most
|
||||
# recently executed command.
|
||||
#
|
||||
# For example, suppose your history has the following entries:
|
||||
# - pwd
|
||||
# - ls foo
|
||||
# - ls bar
|
||||
# - pwd
|
||||
#
|
||||
# Given the history list above, when you type 'ls', the suggestion
|
||||
# will be 'ls foo' rather than 'ls bar' because your most recently
|
||||
# executed command (pwd) was previously followed by 'ls foo'.
|
||||
#
|
||||
# Note that this strategy won't work as expected with ZSH options that don't
|
||||
# preserve the history order such as `HIST_IGNORE_ALL_DUPS` or
|
||||
# `HIST_EXPIRE_DUPS_FIRST`.
|
||||
|
||||
_zsh_autosuggest_strategy_match_prev_cmd() {
|
||||
# Reset options to defaults and enable LOCAL_OPTIONS
|
||||
emulate -L zsh
|
||||
|
||||
# Enable globbing flags so that we can use (#m) and (x~y) glob operator
|
||||
setopt EXTENDED_GLOB
|
||||
|
||||
# TODO: Use (b) flag when we can drop support for zsh older than v5.0.8
|
||||
local prefix="${1//(#m)[\\*?[\]<>()|^~#]/\\$MATCH}"
|
||||
|
||||
# Get the history items that match the prefix, excluding those that match
|
||||
# the ignore pattern
|
||||
local pattern="$prefix*"
|
||||
if [[ -n $ZSH_AUTOSUGGEST_HISTORY_IGNORE ]]; then
|
||||
pattern="($pattern)~($ZSH_AUTOSUGGEST_HISTORY_IGNORE)"
|
||||
fi
|
||||
|
||||
# Get all history event numbers that correspond to history
|
||||
# entries that match the pattern
|
||||
local history_match_keys
|
||||
history_match_keys=(${(k)history[(R)$~pattern]})
|
||||
|
||||
# By default we use the first history number (most recent history entry)
|
||||
local histkey="${history_match_keys[1]}"
|
||||
|
||||
# Get the previously executed command
|
||||
local prev_cmd="$(_zsh_autosuggest_escape_command "${history[$((HISTCMD-1))]}")"
|
||||
|
||||
# Iterate up to the first 200 history event numbers that match $prefix
|
||||
for key in "${(@)history_match_keys[1,200]}"; do
|
||||
# Stop if we ran out of history
|
||||
[[ $key -gt 1 ]] || break
|
||||
|
||||
# See if the history entry preceding the suggestion matches the
|
||||
# previous command, and use it if it does
|
||||
if [[ "${history[$((key - 1))]}" == "$prev_cmd" ]]; then
|
||||
histkey="$key"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
# Give back the matched history entry
|
||||
typeset -g suggestion="$history[$histkey]"
|
||||
}
|
||||
|
||||
#--------------------------------------------------------------------#
|
||||
# Fetch Suggestion #
|
||||
#--------------------------------------------------------------------#
|
||||
# Loops through all specified strategies and returns a suggestion
|
||||
# from the first strategy to provide one.
|
||||
#
|
||||
|
||||
_zsh_autosuggest_fetch_suggestion() {
|
||||
typeset -g suggestion
|
||||
local -a strategies
|
||||
local strategy
|
||||
|
||||
# Ensure we are working with an array
|
||||
strategies=(${=ZSH_AUTOSUGGEST_STRATEGY})
|
||||
|
||||
for strategy in $strategies; do
|
||||
# Try to get a suggestion from this strategy
|
||||
_zsh_autosuggest_strategy_$strategy "$1"
|
||||
|
||||
# Ensure the suggestion matches the prefix
|
||||
[[ "$suggestion" != "$1"* ]] && unset suggestion
|
||||
|
||||
# Break once we've found a valid suggestion
|
||||
[[ -n "$suggestion" ]] && break
|
||||
done
|
||||
}
|
||||
|
||||
#--------------------------------------------------------------------#
|
||||
# Async #
|
||||
#--------------------------------------------------------------------#
|
||||
|
||||
_zsh_autosuggest_async_request() {
|
||||
zmodload zsh/system 2>/dev/null # For `$sysparams`
|
||||
|
||||
typeset -g _ZSH_AUTOSUGGEST_ASYNC_FD _ZSH_AUTOSUGGEST_CHILD_PID
|
||||
|
||||
# If we've got a pending request, cancel it
|
||||
if [[ -n "$_ZSH_AUTOSUGGEST_ASYNC_FD" ]] && { true <&$_ZSH_AUTOSUGGEST_ASYNC_FD } 2>/dev/null; then
|
||||
# Close the file descriptor and remove the handler
|
||||
builtin exec {_ZSH_AUTOSUGGEST_ASYNC_FD}<&-
|
||||
zle -F $_ZSH_AUTOSUGGEST_ASYNC_FD
|
||||
|
||||
# We won't know the pid unless the user has zsh/system module installed
|
||||
if [[ -n "$_ZSH_AUTOSUGGEST_CHILD_PID" ]]; then
|
||||
# Zsh will make a new process group for the child process only if job
|
||||
# control is enabled (MONITOR option)
|
||||
if [[ -o MONITOR ]]; then
|
||||
# Send the signal to the process group to kill any processes that may
|
||||
# have been forked by the suggestion strategy
|
||||
kill -TERM -$_ZSH_AUTOSUGGEST_CHILD_PID 2>/dev/null
|
||||
else
|
||||
# Kill just the child process since it wasn't placed in a new process
|
||||
# group. If the suggestion strategy forked any child processes they may
|
||||
# be orphaned and left behind.
|
||||
kill -TERM $_ZSH_AUTOSUGGEST_CHILD_PID 2>/dev/null
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# Fork a process to fetch a suggestion and open a pipe to read from it
|
||||
builtin exec {_ZSH_AUTOSUGGEST_ASYNC_FD}< <(
|
||||
# Tell parent process our pid
|
||||
echo $sysparams[pid]
|
||||
|
||||
# Fetch and print the suggestion
|
||||
local suggestion
|
||||
_zsh_autosuggest_fetch_suggestion "$1"
|
||||
echo -nE "$suggestion"
|
||||
)
|
||||
|
||||
# There's a weird bug here where ^C stops working unless we force a fork
|
||||
# See https://github.com/zsh-users/zsh-autosuggestions/issues/364
|
||||
autoload -Uz is-at-least
|
||||
is-at-least 5.8 || command true
|
||||
|
||||
# Read the pid from the child process
|
||||
read _ZSH_AUTOSUGGEST_CHILD_PID <&$_ZSH_AUTOSUGGEST_ASYNC_FD
|
||||
|
||||
# When the fd is readable, call the response handler
|
||||
zle -F "$_ZSH_AUTOSUGGEST_ASYNC_FD" _zsh_autosuggest_async_response
|
||||
}
|
||||
|
||||
# Called when new data is ready to be read from the pipe
|
||||
# First arg will be fd ready for reading
|
||||
# Second arg will be passed in case of error
|
||||
_zsh_autosuggest_async_response() {
|
||||
emulate -L zsh
|
||||
|
||||
local suggestion
|
||||
|
||||
if [[ -z "$2" || "$2" == "hup" ]]; then
|
||||
# Read everything from the fd and give it as a suggestion
|
||||
IFS='' read -rd '' -u $1 suggestion
|
||||
zle autosuggest-suggest -- "$suggestion"
|
||||
|
||||
# Close the fd
|
||||
builtin exec {1}<&-
|
||||
fi
|
||||
|
||||
# Always remove the handler
|
||||
zle -F "$1"
|
||||
_ZSH_AUTOSUGGEST_ASYNC_FD=
|
||||
}
|
||||
|
||||
#--------------------------------------------------------------------#
|
||||
# Start #
|
||||
#--------------------------------------------------------------------#
|
||||
|
||||
# Start the autosuggestion widgets
|
||||
_zsh_autosuggest_start() {
|
||||
# By default we re-bind widgets on every precmd to ensure we wrap other
|
||||
# wrappers. Specifically, highlighting breaks if our widgets are wrapped by
|
||||
# zsh-syntax-highlighting widgets. This also allows modifications to the
|
||||
# widget list variables to take effect on the next precmd. However this has
|
||||
# a decent performance hit, so users can set ZSH_AUTOSUGGEST_MANUAL_REBIND
|
||||
# to disable the automatic re-binding.
|
||||
if (( ${+ZSH_AUTOSUGGEST_MANUAL_REBIND} )); then
|
||||
add-zsh-hook -d precmd _zsh_autosuggest_start
|
||||
fi
|
||||
|
||||
_zsh_autosuggest_bind_widgets
|
||||
}
|
||||
|
||||
# Mark for auto-loading the functions that we use
|
||||
autoload -Uz add-zsh-hook is-at-least
|
||||
|
||||
# Automatically enable asynchronous mode in newer versions of zsh. Disable for
|
||||
# older versions because there is a bug when using async mode where ^C does not
|
||||
# work immediately after fetching a suggestion.
|
||||
# See https://github.com/zsh-users/zsh-autosuggestions/issues/364
|
||||
if is-at-least 5.0.8; then
|
||||
typeset -g ZSH_AUTOSUGGEST_USE_ASYNC=
|
||||
fi
|
||||
|
||||
# Start the autosuggestion widgets on the next precmd
|
||||
add-zsh-hook precmd _zsh_autosuggest_start
|
||||
Loading…
Add table
Reference in a new issue