Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2018
761
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 193.88 KB | None | 0 0
  1. #=====================================
  2. #
  3. # OpenBSD Install
  4. #
  5. #=====================================
  6.  
  7. ### Installation ###
  8.  
  9. ## pick shell:
  10.  
  11. s
  12.  
  13. ## wipe drive and clear the dead space:
  14.  
  15. dd if=/dev/urandom of=/dev/rsd0c bs=1m
  16.  
  17. ## encrypt the drive
  18.  
  19. # create efi partition system:
  20.  
  21. fdisk -iy -g -b 960 sd0
  22.  
  23. # make one parition for the whole disk:
  24.  
  25. disklabel -E sd0
  26.  
  27. Label editor (enter '?' for help at any prompt)
  28.  
  29. > a a
  30.  
  31. offset: defaults
  32.  
  33. size: defaults
  34.  
  35. FS type: RAID
  36.  
  37. > w
  38.  
  39. > q
  40.  
  41. No label changes.
  42.  
  43. # encrypt drive:
  44.  
  45. bioctl -c C -l sd0a softraid0
  46.  
  47. # make device node and clear out first megabyte:
  48.  
  49. cd /dev && sh MAKEDEV sd2
  50. dd if=/dev/zero of=/dev/rsd2c bs=1m count=1
  51.  
  52. ## installer
  53.  
  54. # start installer
  55.  
  56. exit and choose installer:
  57.  
  58. exit
  59.  
  60. i
  61.  
  62. # pick keyboard:
  63.  
  64. US QWERTY
  65.  
  66. # hostname:
  67.  
  68. host
  69.  
  70. # wireless:
  71.  
  72. skip:
  73. done
  74.  
  75. # DNS domain name:
  76.  
  77. default
  78.  
  79. # password for root:
  80.  
  81. *type password*
  82.  
  83. # start sshd:
  84.  
  85. no
  86.  
  87. # start the x window system by xenodm:
  88.  
  89. yes
  90.  
  91. # user setup:
  92.  
  93. # setup a user: user
  94.  
  95. # full name: User
  96.  
  97. # password for user: *enter password*
  98.  
  99. # which disk is the root disk:
  100.  
  101. sd2
  102.  
  103. # use whole disk with MBR or GPT:
  104.  
  105. gtp
  106.  
  107. # use auto layout
  108.  
  109. a
  110.  
  111. # location of sets:
  112.  
  113. disk
  114.  
  115. # Is the disk partition already mounted?:
  116.  
  117. no
  118.  
  119. # Which disk contains the install media? (or 'done'):
  120.  
  121. sd1
  122.  
  123. # Available sd1 partitions are:
  124.  
  125. a
  126.  
  127. # Which sd1 partition has the install sets? (or 'done')
  128.  
  129. [a]
  130.  
  131. # Pathname to the sets? (or 'done'):
  132.  
  133. [6.4/amd64]
  134.  
  135. # what timezone:
  136.  
  137. UTC
  138.  
  139. # reboot
  140.  
  141. ### Post Installation ###
  142.  
  143. ## login as root:
  144.  
  145. username: root
  146.  
  147. password: *enter root password*
  148.  
  149. ## disable bell
  150.  
  151. # ttys
  152. wsconsctl keyboard.bell.volume=0
  153.  
  154. edit /etc/wsconsctl.conf:
  155. # disable bell
  156. keyboard.bell.volume=0
  157.  
  158. # xorg
  159.  
  160. echo 'xset b off' >> /etc/X11/xenodm/Xsetup_0
  161.  
  162. ## network
  163.  
  164. # setup with ethernet
  165.  
  166. # find ethernet interface:
  167.  
  168. ifconfig
  169.  
  170. # setup ethernet:
  171.  
  172. dhclient em0
  173.  
  174. # get and install wifi firmware:
  175.  
  176. fw_update
  177.  
  178. # setup wifi card and find wifi:
  179.  
  180. ifconfig iwn0 up
  181.  
  182. ifconfig iwn0 scan
  183.  
  184. # connect to wifi
  185.  
  186. ifconfig iwn0 nwid YOUR_SSID wpakey "YOUR_PASSPHRASE"
  187.  
  188. dhclient iwn0
  189.  
  190. # create /etc/hostname.iwn0 with the following:
  191.  
  192. vi /etc/hostname.iwn0:
  193.  
  194. # add networks in order of priority, for example:
  195.  
  196. # join "HOME_SSID" wpakey "HOME_PASSPHRASE"
  197.  
  198. # join "WORK_SSID" wpakey "WORK_PASSPHRASE"
  199.  
  200. # join "OPEN_COFFEE_SHOP"
  201.  
  202. # home:
  203.  
  204. join "SSID" wpakey "PASSPHRASE"
  205.  
  206. dhcp
  207.  
  208. inet6 autoconf
  209.  
  210. up powersave
  211.  
  212. # test changes:
  213.  
  214. ifconfig em0 down
  215.  
  216. ifconfig iwn0 down
  217.  
  218. pkill dhclient
  219.  
  220. sh /etc/netstart
  221.  
  222. # if that doesn't work reboot
  223.  
  224. # set usb mount directory and test usb mounting
  225. mkdir /mnt/usb
  226.  
  227. chown user:user /mnt/usb
  228.  
  229. mount -t msdos /dev/sd2i /mnt/usb
  230.  
  231. # disable xconsole window from autostarting at each login:
  232.  
  233. sed -i 's/xconsole/#xconsole/' /etc/X11/xenodm/Xsetup_0
  234.  
  235. # remap keys
  236.  
  237. ## map caps lock to esacpe key in tty:
  238.  
  239. # tty
  240. vi /etc/wsconsctl.conf:
  241.  
  242. keyboard.map+="keysym Caps_Lock = Escape"
  243.  
  244. # set UTF-8 for tty:
  245.  
  246. export LANG=en_US.UTF-8
  247.  
  248. export LC_ALL=en_US.UTF-8
  249.  
  250. # and add it to /etc/login.conf
  251.  
  252. :charset=UTF-8:\
  253. :LANG=en_US.UTF-8:\
  254. :LC_ALL=en_US.UTF-8:
  255.  
  256. # setup doas for user:
  257.  
  258. echo 'permit persist keepenv user' > /etc/doas.conf
  259.  
  260. # enable power managemnt options:
  261.  
  262. rcctl enable apmd
  263.  
  264. rcctl set apmd flags -A
  265.  
  266. rcctl start apmd
  267.  
  268. # add user to groups:
  269.  
  270. usermod -G staff user
  271.  
  272. usermod -G operator
  273.  
  274. usermod -G games
  275.  
  276. # change resource limits:
  277.  
  278. vi /etc/login.conf:
  279.  
  280. staff:\
  281. :datasize-cur=1024M:\
  282. :datasize-max=8192M:\
  283. :maxproc-cur=512:\
  284. :maxproc-max=1024:\
  285. :openfiles-cur=4096:\
  286. :openfiles-max=8192:\
  287. :stacksize-cur=32M:\
  288. :ignorenologin:\
  289. :requirehome@:\
  290. :tc=default:
  291.  
  292. # bump up kernal sysctls:
  293.  
  294. vi /etc/sysctl.conf:
  295.  
  296. # shared memory limits
  297. kern.shminfo.shmall=3145728
  298. kern.shminfo.shmmax=2147483647
  299. kern.shminfo.shmmni=1024
  300.  
  301. # semaphores
  302. kern.shminfo.shmseg=1024
  303. kern.seminfo.semmns=4096
  304. kern.seminfo.semmni=1024
  305.  
  306. kern.maxproc=32768
  307. kern.maxfiles=65535
  308. kern.bufcachepercent=90
  309. kern.maxvnodes=262144
  310. kern.somaxconn=2048
  311.  
  312. # lock screen automaticaly when you close the lid:
  313.  
  314. # make the directory for apm:
  315.  
  316. mkdir /etc/apm
  317.  
  318. # Then, create the file /etc/apm/suspend with the following contents:
  319.  
  320. #!/bin/sh
  321. pkill -USR1 xidle
  322.  
  323. # And make it executable:
  324.  
  325. chmod +x /etc/apm/suspend
  326.  
  327. # turn off ntpd google check:
  328.  
  329. sed -i '/google/d' /etc/ntpd.conf
  330.  
  331. # restart ntpd:
  332.  
  333. rcctl restart ntpd
  334.  
  335. # change hostname:
  336.  
  337. vi /etc/myname:
  338.  
  339. host
  340.  
  341. # exit and login as user
  342.  
  343. # uninstall fvwm
  344.  
  345. ## install ports tree
  346.  
  347. # fetch the ports tree:
  348.  
  349. cd /tmp
  350.  
  351. ftp https://cdn.openbsd.org/pub/OpenBSD/$(uname -r)/{ports.tar.gz,SHA256.sig}
  352.  
  353. signify -Cp /etc/signify/openbsd-$(uname -r | cut -c 1,3)-base.pub -x SHA256.sig ports.tar.gz
  354.  
  355. # untar the ports tree in /usr/ports:
  356.  
  357. cd /usr
  358.  
  359. tar xzf /tmp/ports.tar.gz
  360.  
  361. # configure ports:
  362.  
  363. # vi /etc/mk.conf:
  364.  
  365. WRKOBJDIR=/usr/obj/ports
  366.  
  367. DISTDIR=/usr/distfiles
  368.  
  369. PACKAGE_REPOSITORY=/usr/packages
  370.  
  371. ## install programs
  372.  
  373. # shell:
  374.  
  375. ## zsh:
  376.  
  377. doas pkg_add zsh
  378.  
  379. # editor:
  380.  
  381. ## neovim:
  382.  
  383. doas pkg_add neovim
  384.  
  385. # music and video:
  386.  
  387. ## mpd:
  388.  
  389. doas pkg_add mpd
  390.  
  391. ## mpc:
  392.  
  393. doas pkg_add mpc
  394.  
  395. ## ncmpcpp:
  396.  
  397. doas pkg_add ncmpcpp
  398.  
  399. ## ncmpc:
  400.  
  401. doas pkg_add ncmpc
  402.  
  403. ## mpv:
  404.  
  405. doas pkg_add mpv
  406.  
  407. # network:
  408.  
  409. ## tor:
  410.  
  411. doas pkg_add tor
  412.  
  413. # web browsing
  414.  
  415. ## tor-browser:
  416.  
  417. doas pkg_add tor-browser
  418.  
  419. ## firefox:
  420.  
  421. doas pkg_add firefox
  422.  
  423. ## qutebrowser:
  424.  
  425. doas pkg_add qutebrowser
  426.  
  427. ## w3m:
  428.  
  429. doas pkg_add w3m
  430.  
  431. choice: (2)
  432.  
  433. # file management:
  434.  
  435. ## thunar:
  436.  
  437. doas pkg_add thunar
  438.  
  439. ## ranger:
  440.  
  441. doas pkg_add ranger
  442.  
  443. # utilities:
  444.  
  445. ## feh:
  446.  
  447. doas pkg_add feh
  448.  
  449. ## dunst:
  450.  
  451. doas pkg_add dunst
  452.  
  453. ## tree:
  454.  
  455. doas pkg_add tree
  456.  
  457. ## scrot:
  458.  
  459. doas pkg_add scrot
  460.  
  461. ## neofetch:
  462.  
  463. doas pkg_add neofetch
  464.  
  465. ## htop:
  466.  
  467. doas pkg_add htop
  468.  
  469. ## wget:
  470.  
  471. doas pkg_add wget
  472.  
  473. ## git:
  474.  
  475. doas pkg_add git
  476.  
  477. ## gimp:
  478.  
  479. doas pkg_add gimp
  480.  
  481. ## transmission:
  482.  
  483. doas pkg_add transmission
  484.  
  485. ## unzip:
  486.  
  487. doas pkg_add unzip
  488.  
  489. choice (1)
  490.  
  491. ## zathura:
  492.  
  493. doas pkg_add zathura
  494.  
  495. ## qemu:
  496.  
  497. doas pkg_add qemu
  498.  
  499. ## imagemagick:
  500.  
  501. doas pkg_add ImageMagick
  502.  
  503. # social media:
  504.  
  505. ## pidgin:
  506.  
  507. doas pkg_add pidgin
  508.  
  509. choice (1)
  510.  
  511. ## pidgin-otr:
  512.  
  513. doas pkg_add pidgin-otr
  514.  
  515. ## pidgin-libnotify:
  516.  
  517. doas pkg_add pidgin-libnotify
  518.  
  519. ## irssi:
  520.  
  521. doas pkg_add irssi
  522.  
  523. choice (2)
  524.  
  525. ## irssi-otr:
  526.  
  527. doas pkg_add irssi-otr
  528.  
  529. ## neomutt:
  530.  
  531. doas pkg_add neomutt
  532.  
  533. choice (1)
  534.  
  535. # programming
  536.  
  537. ## ipython:
  538.  
  539. doas pkg_add ipython
  540.  
  541. ## py-virtualenv:
  542.  
  543. doas pkg_add py-virtualenv
  544.  
  545. ## py3-virtualenv:
  546.  
  547. doas pkg_add py3-virtualenv
  548.  
  549. ## py-pip:
  550.  
  551. doas pkg_add py-pip
  552.  
  553. ## py3-pip:
  554.  
  555. doas pkg_add py3-pip
  556.  
  557. # games
  558.  
  559. ## wesnoth:
  560.  
  561. doas pkg_add wesnoth
  562.  
  563. ## 0ad:
  564.  
  565. doas pkg_add 0ad
  566.  
  567. ## minetest:
  568.  
  569. doas pkg_add mintest
  570.  
  571. ## nethack:
  572.  
  573. doas pkg_add nethack
  574.  
  575. choice (2)
  576.  
  577. ## supertux:
  578.  
  579. doas pkg_add supertux
  580.  
  581. ## supertuxkart:
  582.  
  583. doas pkg_add supertuxkart
  584.  
  585. # terminal
  586.  
  587. ## urxvt-unicode:
  588.  
  589. doas pkg_add urxvt-unicode
  590.  
  591. # fonts
  592.  
  593. ## noto-fonts:
  594.  
  595. doas pkg_add noto-fonts
  596.  
  597. ## liberation-fonts:
  598.  
  599. doas pkg_add liberation-fonts
  600.  
  601. ## zh-fonts-arphicttf:
  602.  
  603. doas pkg_add zh-fonts-arphicttf
  604.  
  605. ## terminus-font:
  606.  
  607. doas pkg_add terminus-font
  608.  
  609. choice (1: terminus-font)
  610.  
  611. ## p5-Locale-Hebrew:
  612.  
  613. doas pkg_add p5-Locale-Hebrew
  614.  
  615. ## migmix:
  616.  
  617. doas pkg_add migmix
  618.  
  619. ## migu:
  620.  
  621. doas pkg_add migu
  622.  
  623. ## ja-sazanami-ttf:
  624.  
  625. doas pkg_add ja-sazanami-ttf
  626.  
  627. ## vlgothic:
  628.  
  629. doas pkg_add vlgothic
  630.  
  631. ## hanazono:
  632.  
  633. doas pkg_add hanazono
  634.  
  635. ## anonymous-pro:
  636.  
  637. doas pkg_add anonymous-pro
  638.  
  639. ## artwiz-aleczapka:
  640.  
  641. doas pkg_add artwiz-aleczapka
  642.  
  643. ## inconsolata-font:
  644.  
  645. doas pkg_add inconsolata-font
  646.  
  647. ## cantarell-fonts:
  648.  
  649. doas pkg_add cantarell-fonts
  650.  
  651. ## doulos:
  652.  
  653. doas pkg_add doulos
  654.  
  655. ## ubuntu-fonts:
  656.  
  657. doas pkg_add ubuntu-fonts
  658.  
  659. ## junicode:
  660.  
  661. doas pkg_add junicode
  662.  
  663. ## charis:
  664.  
  665. doas pkg_add charis
  666.  
  667. ## gentium:
  668.  
  669. doas pkg_add gentium
  670.  
  671. ## powerline-fonts:
  672.  
  673. doas pkg_add powerline-fonts
  674.  
  675. # make a build directory:
  676.  
  677. mkdir .builds
  678.  
  679. # window manageer
  680.  
  681. ## dwm
  682.  
  683. cd .builds
  684.  
  685. git clone git://git.suckless.org/dwm
  686.  
  687. cd dwm
  688.  
  689. # uncomment openbsd libs in config.mk:
  690.  
  691. # OpenBSD (uncomment)
  692. FREETYPEINC = ${X11INC}/freetype2
  693.  
  694. # build dwm:
  695.  
  696. doas make clean install
  697.  
  698. # application menu
  699.  
  700. ## demenu
  701.  
  702. cd .builds
  703.  
  704. git clone git://git.suckless.org/dmenu
  705.  
  706. cd dmenu
  707.  
  708. # uncomment openbsd libs in config.mk:
  709.  
  710. FREETYPEINC = ${X11INC}/freetype2
  711.  
  712. # build dmenu:
  713.  
  714. doas make clean install
  715.  
  716. # make subdirecories and change shell:
  717.  
  718. mkdir Documents Downloads Music Videos Pictures
  719.  
  720. mkdir Pictures/.screenshots
  721.  
  722. mkdir ~/.config
  723.  
  724. doas mkdir /usr/local/share/backgrounds
  725.  
  726. # change shell for user:
  727.  
  728. chsh -s /usr/local/bin/zsh
  729.  
  730. # move files to the right places:
  731.  
  732. doas mv Fonts /usr/local/share/fonts
  733.  
  734. doas mv wallpapers /usr/local/share/backgrounds
  735.  
  736. ### Configurations ###
  737.  
  738. ============================================================================================================================
  739.  
  740. ## .xsession:
  741.  
  742. vi ~/.xsessions
  743.  
  744. #####################
  745. #
  746. # .xsession
  747. #
  748. #####################
  749.  
  750.  
  751. # use UTF-8 everywhere
  752. export LANG=en_US.UTF-8
  753.  
  754. # specify location of .zshrc
  755. export ENV=$HOME/.zshrc
  756.  
  757. # load .Xresources
  758. xrdb -merge $HOME/.Xresources
  759.  
  760. # set background color
  761. xsetroot -solid back
  762.  
  763. # enable scrolling with trackpoint and middle button
  764. xinput set-prop "/dev/wsmouse" "WS Pointer Wheel Emulation" 1
  765. xinput set-prop "/dev/wsmouse" "WS Pointer Wheel Emulation Button" 2
  766. xinput set-prop "/dev/wsmouse" "WS Pointer Wheel Emulation Axes" 6 7 4 5
  767.  
  768. # remap caps lock to esacpe
  769. setxkbmap -option caps:escape
  770.  
  771. # start dwm
  772. exec dwm
  773.  
  774. ============================================================================================================================
  775.  
  776. ## .Xresources:
  777.  
  778. vi ~/.Xresources
  779.  
  780. !!!!!!!!!!!!!!!!!!!!!!!!!!
  781. !
  782. ! .Xresources
  783. !
  784. !!!!!!!!!!!!!!!!!!!!!!!!!!
  785.  
  786. ! to load .Xresources run:
  787.  
  788. ! xrdb ~/.Xresources
  789.  
  790. ! ===== fonts
  791.  
  792. !to find which font is used as the fall back font for a specific character run:
  793.  
  794. ! FC_DEBUG=4 pango-view -q -t '{character}' 2>&1 |\grep -o 'family: "[^"]\+' | cut -c 10- | tail -n 1
  795.  
  796. !to find the name of a font:
  797.  
  798. ! fc-list -v | grep *name*
  799.  
  800. Xft.autohint : 0
  801. Xft.lcdfilter : lcddefault
  802. Xft.hintstyle : hintslight
  803. Xft.hinting : 1
  804. Xft.antialias : 1
  805. Xft.rgba : rgb
  806. *font : Terminus (TTF):size=9
  807.  
  808. ! ===== urxvt:
  809.  
  810. ! fonts
  811. URxvt.font: xft:Terminus (TTF):size=9, xft:Noto Sans Devanagari:9, xft:Noto Emoji, xft:DejaVu Serif, xft:Noto Sans Kannada
  812.  
  813. ! scrollbar
  814. URxvt.scrollBar: false
  815.  
  816. ! scrollback
  817. URxvt*.saveLines: 10000
  818.  
  819. ! transparency
  820. URxvt.depth: 32
  821. URxvt.background: [95]#000000
  822.  
  823. ! fading
  824. URxvt*fading: 30
  825.  
  826. ! cursor
  827. URxvt*cursorUnderline: true
  828. URxvt*cursorBlink: true
  829. URxvt*cursorColor: #FF0099
  830.  
  831. !! theme
  832. !background color
  833. URxvt*background: #000000
  834.  
  835. ! font color
  836. URxvt*foreground: #67C8FF
  837.  
  838. ! other colors
  839. URxvt*color0: #000000
  840. URxvt*color1: #FF0000
  841. URxvt*color2: #67C8FF
  842. URxvt*color3: #FF1493
  843. URxvt*color4: #099FFF
  844. URxvt*color5: #CC00FF
  845. URxvt*color6: #099FFF
  846. URxvt*color7: #820571
  847. URxvt*color8: #45013C
  848. URxvt*color9: #099FFF
  849. URxvt*color10: #FF0099
  850. URxvt*color11: #E6FB04
  851. URxvt*color12: #9400D3
  852. URxvt*color13: #DB329D
  853. URxvt*color14: #9400D3
  854. URxvt*color15: #FF0099
  855. URxvt*underlineColor: #FF34B3
  856. URxvt*highlightColor: #191970
  857. URxvt*highlightTextColor: #EE00EE
  858.  
  859. !! extensions
  860.  
  861. !fullscreen
  862. URxvt.perl-ext-common: fullscreen
  863. URxvt.keysym.F11: perl:fullscreen:switch
  864.  
  865. ! ===== xterm
  866.  
  867. !! theme
  868.  
  869. XTerm*background : #000000
  870. XTerm*foreground : #67C8FF
  871. XTerm*cursorColor : #FF0099
  872. XTerm*colorUL : #366060
  873. XTerm*underlineColor : #FF34B3
  874. XTerm*color0 : #000000
  875. XTerm*color1 : #FF0000
  876. XTerm*color2 : #67C8FF
  877. XTerm*color3 : #FF1493
  878. XTerm*color4 : #099FFF
  879. XTerm*color5 : #CC00FF
  880. XTerm*color6 : #099FFF
  881. XTerm*color7 : #820571
  882. XTerm*color8 : #45013C
  883. XTerm*color9 : #099FFF
  884. XTerm*color10 : #FF0099
  885. XTerm*color11 : #E6FB04
  886. XTerm*color12 : #9400D3
  887. XTerm*color13 : #DB329D
  888. XTerm*color14 : #9400D3
  889. XTerm*color15 : #FF0099
  890.  
  891. ! remove the additional black border
  892. XTerm*borderWidth : 0
  893. XTerm*internalBorder : 2
  894.  
  895. ! set TERM env variable to use 256 colors
  896. XTerm*termName : xterm-256color
  897.  
  898. ! make alt key work normally
  899. XTerm*vt100.metaSendsEscape : true
  900.  
  901. ! save ~10,000 lines of scrollback
  902. XTerm*v100.saveLines : 10240
  903.  
  904. ! hide scrollbar
  905. XTerm*vt100.scrollBar : false
  906.  
  907. ! some black magic to change what characters XTerm considers "word delimiters"
  908. XTerm*charClass : 33:48,36-47:48,58-59:48,61:48,63-64:48,95:48,126:48
  909.  
  910. ============================================================================================================================
  911.  
  912. ## GTK3 settings
  913.  
  914. # make the file:
  915.  
  916. mkdir -p ~/.config/gtk-3.0
  917.  
  918. # vi ~/.config/gtk-3.0/settings.ini:
  919.  
  920. [Settings]
  921. gtk-theme-name=Adwaita
  922. gtk-icon-theme-name=Adwaita
  923. gtk-font-name=Arimo 9
  924. gtk-toolbar-style=GTK_TOOLBAR_ICONS
  925. gtk-toolbar-icon-size=GTK_ICON_SIZE_SMALL_TOOLBAR
  926. gtk-button-images=1
  927. gtk-menu-images=1
  928. gtk-enable-event-sounds=1
  929. gtk-enable-input-feedback-sounds=0
  930. gtk-xft-antialias=1
  931. gtk-xft-hinting=1
  932. gtk-xft-hintstyle=hintslight
  933. gtk-xft-rgba=rgb
  934. gtk-cursor-theme-size=0
  935. gtk-cursor-theme-name=Default
  936. gtk-key-theme-name=Default
  937.  
  938. ============================================================================================================================
  939.  
  940. ## dwm (config.def.h)
  941.  
  942. ## to rebuild for changes to take affect do the following:
  943.  
  944. # copy config.def.h to config.h:
  945.  
  946. doas cp confg.def.h config.h
  947.  
  948. # rebuild and install:
  949.  
  950. doas make clean install
  951.  
  952. /* See LICENSE file for copyright and license details. */
  953.  
  954. /* appearance */
  955. static const unsigned int borderpx = 1; /* border pixel of windows */
  956. static const unsigned int snap = 32; /* snap pixel */
  957. static const int showbar = 1; /* 0 means no bar */
  958. static const int topbar = 1; /* 0 means bottom bar */
  959. static const char *fonts[] = { "Terminus (TTF):size=9" };
  960. static const char dmenufont[] = "Sparkles:size=9";
  961. static const char col_black1[] = "#000000";
  962. static const char col_gray2[] = "#444444";
  963. static const char col_gray3[] = "#bbbbbb";
  964. static const char col_gray4[] = "#eeeeee";
  965. static const char col_cyan[] = "#67C8FF";
  966. static const char *colors[][3] = {
  967. /* fg bg border */
  968. [SchemeNorm] = { col_gray3, col_black1, col_gray2 },
  969. [SchemeSel] = { col_gray4, col_black1, col_cyan },
  970. };
  971.  
  972. /* tagging */
  973. static const char *tags[] = { "零", "一", "二", "三", "四", "五", " 六", "七", "八" };
  974.  
  975. static const Rule rules[] = {
  976. /* xprop(1):
  977. * WM_CLASS(STRING) = instance, class
  978. * WM_NAME(STRING) = title
  979. */
  980. /* class instance title tags mask isfloating monitor */
  981. { "Gimp", NULL, NULL, 0, 1, -1 },
  982. { "Firefox", NULL, NULL, 1 << 8, 0, -1 },
  983. };
  984.  
  985. /* layout(s) */
  986. static const float mfact = 0.55; /* factor of master area size [0.05..0.95] */
  987. static const int nmaster = 1; /* number of clients in master area */
  988. static const int resizehints = 1; /* 1 means respect size hints in tiled resizals */
  989.  
  990. static const Layout layouts[] = {
  991. /* symbol arrange function */
  992. { "[]=", tile }, /* first entry is default */
  993. { "><>", NULL }, /* no layout function means floating behavior */
  994. { "[M]", monocle },
  995. };
  996.  
  997. /* key definitions */
  998. #define MODKEY Mod4Mask
  999. #define TAGKEYS(KEY,TAG) \
  1000. { MODKEY, KEY, view, {.ui = 1 << TAG} }, \
  1001. { MODKEY|ControlMask, KEY, toggleview, {.ui = 1 << TAG} }, \
  1002. { MODKEY|ShiftMask, KEY, tag, {.ui = 1 << TAG} }, \
  1003. { MODKEY|ControlMask|ShiftMask, KEY, toggletag, {.ui = 1 << TAG} },
  1004.  
  1005. /* helper for spawning shell commands in the pre dwm-5.0 fashion */
  1006. #define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } }
  1007.  
  1008. /* commands */
  1009. static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn() */
  1010. static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_black1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL };
  1011. static const char *termcmd[] = { "urxvt", NULL };
  1012.  
  1013. static Key keys[] = {
  1014. /* modifier key function argument */
  1015. { MODKEY, XK_d, spawn, {.v = dmenucmd } },
  1016. { MODKEY, XK_Return, spawn, {.v = termcmd } },
  1017. { MODKEY, XK_b, togglebar, {0} },
  1018. { MODKEY, XK_j, focusstack, {.i = +1 } },
  1019. { MODKEY, XK_k, focusstack, {.i = -1 } },
  1020. { MODKEY, XK_h, incnmaster, {.i = +1 } },
  1021. { MODKEY, XK_v, incnmaster, {.i = -1 } },
  1022. { MODKEY, XK_i, setmfact, {.f = -0.05} },
  1023. { MODKEY, XK_l, setmfact, {.f = +0.05} },
  1024. { MODKEY|ShiftMask, XK_Return, zoom, {0} },
  1025. { MODKEY, XK_Tab, view, {0} },
  1026. { MODKEY|ShiftMask, XK_p, killclient, {0} },
  1027. { MODKEY, XK_t, setlayout, {.v = &layouts[0]} },
  1028. { MODKEY, XK_f, setlayout, {.v = &layouts[1]} },
  1029. { MODKEY, XK_m, setlayout, {.v = &layouts[2]} },
  1030. { MODKEY, XK_space, setlayout, {0} },
  1031. { MODKEY|ShiftMask, XK_space, togglefloating, {0} },
  1032. { MODKEY, XK_0, view, {.ui = ~0 } },
  1033. { MODKEY|ShiftMask, XK_0, tag, {.ui = ~0 } },
  1034. { MODKEY, XK_comma, focusmon, {.i = -1 } },
  1035. { MODKEY, XK_period, focusmon, {.i = +1 } },
  1036. { MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } },
  1037. { MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } },
  1038. TAGKEYS( XK_1, 0)
  1039. TAGKEYS( XK_2, 1)
  1040. TAGKEYS( XK_3, 2)
  1041. TAGKEYS( XK_4, 3)
  1042. TAGKEYS( XK_5, 4)
  1043. TAGKEYS( XK_6, 5)
  1044. TAGKEYS( XK_7, 6)
  1045. TAGKEYS( XK_8, 7)
  1046. TAGKEYS( XK_9, 8)
  1047. { MODKEY|ShiftMask, XK_q, quit, {0} },
  1048. };
  1049.  
  1050. /* button definitions */
  1051. /* click can be ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle, ClkClientWin, or ClkRootWin */
  1052. static Button buttons[] = {
  1053. /* click event mask button function argument */
  1054. { ClkLtSymbol, 0, Button1, setlayout, {0} },
  1055. { ClkLtSymbol, 0, Button3, setlayout, {.v = &layouts[2]} },
  1056. { ClkWinTitle, 0, Button2, zoom, {0} },
  1057. { ClkStatusText, 0, Button2, spawn, {.v = termcmd } },
  1058. { ClkClientWin, MODKEY, Button1, movemouse, {0} },
  1059. { ClkClientWin, MODKEY, Button2, togglefloating, {0} },
  1060. { ClkClientWin, MODKEY, Button3, resizemouse, {0} },
  1061. { ClkTagBar, 0, Button1, view, {0} },
  1062. { ClkTagBar, 0, Button3, toggleview, {0} },
  1063. { ClkTagBar, MODKEY, Button1, tag, {0} },
  1064. { ClkTagBar, MODKEY, Button3, toggletag, {0} },
  1065. };
  1066.  
  1067. ============================================================================================================================
  1068.  
  1069. ## Zsh
  1070.  
  1071. ##################################
  1072. #
  1073. # ZSH Config
  1074. #
  1075. ##################################
  1076.  
  1077. ### Global Settings ###
  1078.  
  1079. ## completions
  1080. zstyle :compinstall filename '/home/user/.zshrc'
  1081. autoload -Uz compinit
  1082. compinit
  1083.  
  1084. ## enable highlighting
  1085. zstyle ':completion:*' menu select=1
  1086.  
  1087. ## corrections settings
  1088. zstyle ':completion:*' completer _complete _approximate
  1089.  
  1090. ## automatically change directory if a directory is entered
  1091. setopt autocd
  1092. setopt extendedglob
  1093.  
  1094. ## case-insensitive globbing
  1095. zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
  1096.  
  1097. ## history settings
  1098. HISTFILE=~/.zsh_history
  1099. HISTSIZE=20000
  1100. SAVEHIST=$HISTSIZE
  1101.  
  1102. ######################################################################################################################
  1103.  
  1104. ### Keybindings ###
  1105.  
  1106. if [[ ${terminfo[smkx]} && ${terminfo[rmkx]} ]]
  1107. then
  1108. function zle-line-init {
  1109. echoti smkx
  1110. }
  1111. function zle-line-finish {
  1112. echoti rmkx
  1113. }
  1114. zle -N zle-line-init
  1115. zle -N zle-line-finish
  1116. fi
  1117.  
  1118. # Create a hashmap from key names to their codes.
  1119. typeset -gA key
  1120.  
  1121. key[Home]=${terminfo[khome]}
  1122. key[End]=${terminfo[kend]}
  1123. key[Insert]=${terminfo[kich1]}
  1124. key[Delete]=${terminfo[kdch1]}
  1125. key[Up]=${terminfo[kcuu1]}
  1126. key[Down]=${terminfo[kcud1]}
  1127. key[Left]=${terminfo[kcub1]}
  1128. key[Right]=${terminfo[kcuf1]}
  1129.  
  1130. key[Shift-Home]=${terminfo[kHOM]}
  1131. key[Shift-End]=${terminfo[kEND]}
  1132. key[Shift-Insert]=${terminfo[kIC]}
  1133. key[Shift-Delete]=${terminfo[kDC]}
  1134. key[Shift-Up]=${terminfo[kUP]}
  1135. key[Shift-Down]=${terminfo[kDN]}
  1136. key[Shift-Left]=${terminfo[kLFT]}
  1137. key[Shift-Right]=${terminfo[kRIT]}
  1138.  
  1139. key[Alt-Home]=${terminfo[kHOM3]}
  1140. key[Alt-End]=${terminfo[kEND3]}
  1141. key[Alt-Insert]=${terminfo[kIC3]}
  1142. key[Alt-Delete]=${terminfo[kDC3]}
  1143. key[Alt-Up]=${terminfo[kUP3]}
  1144. key[Alt-Down]=${terminfo[kDN3]}
  1145. key[Alt-Left]=${terminfo[kLFT3]}
  1146. key[Alt-Right]=${terminfo[kRIT3]}
  1147.  
  1148. key[Shift-Alt-Home]=${terminfo[kHOM4]}
  1149. key[Shift-Alt-End]=${terminfo[kEND4]}
  1150. key[Shift-Alt-Insert]=${terminfo[kIC4]}
  1151. key[Shift-Alt-Delete]=${terminfo[kDC4]}
  1152. key[Shift-Alt-Up]=${terminfo[kUP4]}
  1153. key[Shift-Alt-Down]=${terminfo[kDN4]}
  1154. key[Shift-Alt-Left]=${terminfo[kLFT4]}
  1155. key[Shift-Alt-Right]=${terminfo[kRIT4]}
  1156.  
  1157. key[Ctrl-Home]=${terminfo[kHOM5]}
  1158. key[Ctrl-End]=${terminfo[kEND5]}
  1159. key[Ctrl-Insert]=${terminfo[kIC5]}
  1160. key[Ctrl-Delete]=${terminfo[kDC5]}
  1161. key[Ctrl-Up]=${terminfo[kUP5]}
  1162. key[Ctrl-Down]=${terminfo[kDN5]}
  1163. key[Ctrl-Left]=${terminfo[kLFT5]}
  1164. key[Ctrl-Right]=${terminfo[kRIT5]}
  1165.  
  1166. key[Shift-Ctrl-Home]=${terminfo[kHOM6]}
  1167. key[Shift-Ctrl-End]=${terminfo[kEND6]}
  1168. key[Shift-Ctrl-Insert]=${terminfo[kIC6]}
  1169. key[Shift-Ctrl-Delete]=${terminfo[kDC6]}
  1170. key[Shift-Ctrl-Up]=${terminfo[kUP6]}
  1171. key[Shift-Ctrl-Down]=${terminfo[kDN6]}
  1172. key[Shift-Ctrl-Left]=${terminfo[kLFT6]}
  1173. key[Shift-Ctrl-Right]=${terminfo[kRIT6]}
  1174.  
  1175. key[Alt-Ctrl-Home]=${terminfo[kHOM7]}
  1176. key[Alt-Ctrl-End]=${terminfo[kEND7]}
  1177. key[Alt-Ctrl-Insert]=${terminfo[kIC7]}
  1178. key[Alt-Ctrl-Delete]=${terminfo[kDC7]}
  1179. key[Alt-Ctrl-Up]=${terminfo[kUP7]}
  1180. key[Alt-Ctrl-Down]=${terminfo[kDN7]}
  1181. key[Alt-Ctrl-Left]=${terminfo[kLFT7]}
  1182. key[Alt-Ctrl-Right]=${terminfo[kRIT7]}
  1183.  
  1184. key[Shift-Alt-Ctrl-Home]='' # TODO
  1185. key[Shift-Alt-Ctrl-End]='' # TODO
  1186. key[Shift-Alt-Ctrl-Insert]='' # TODO
  1187. key[Shift-Alt-Ctrl-Delete]='' # TODO
  1188. key[Shift-Alt-Ctrl-Up]='' # TODO
  1189. key[Shift-Alt-Ctrl-Down]='' # TODO
  1190. key[Shift-Alt-Ctrl-Left]='' # TODO
  1191. key[Shift-Alt-Ctrl-Right]='' # TODO
  1192.  
  1193. # Other keys:
  1194. # The traditional effect of the Alt-Key is to send Esc then Key.
  1195. key[Backspace]='^?'
  1196. key[Alt-Backspace]='\e^?'
  1197. key[Prior]=${terminfo[kpp]}
  1198. key[Next]=${terminfo[knp]}
  1199. key[Tab]='\t'
  1200. key[Shift-Tab]=${terminfo[kcbt]}
  1201.  
  1202. # Key bindings:
  1203. # Now that our keycodes are defined, we actually bind them to ZLE widgets.
  1204. bindkey -v # Default to emacs key bindings for many widgets.
  1205. [[ ${key[Home]} ]] && bindkey ${key[Home]} beginning-of-line
  1206. [[ ${key[End]} ]] && bindkey ${key[End]} end-of-line
  1207. [[ ${key[Insert]} ]] && bindkey ${key[Insert]} overwrite-mode
  1208. [[ ${key[Delete]} ]] && bindkey ${key[Delete]} delete-char
  1209. [[ ${key[Up]} ]] && bindkey ${key[Up]} up-line-or-search
  1210. [[ ${key[Down]} ]] && bindkey ${key[Down]} down-line-or-search
  1211. [[ ${key[Left]} ]] && bindkey ${key[Left]} backward-char
  1212. [[ ${key[Right]} ]] && bindkey ${key[Right]} forward-char
  1213. [[ ${key[Ctrl-Left]} ]] && bindkey ${key[Ctrl-Left]} backward-word
  1214. [[ ${key[Ctrl-Right]} ]] && bindkey ${key[Ctrl-Right]} forward-word
  1215. [[ ${key[Alt-Left]} ]] && bindkey ${key[Alt-Left]} backward-word
  1216. [[ ${key[Alt-Right]} ]] && bindkey ${key[Alt-Right]} forward-word
  1217. [[ ${key[Tab]} ]] && bindkey ${key[Tab]} menu-expand-or-complete
  1218. [[ ${key[Shift-Tab]} ]] && bindkey ${key[Shift-Tab]} reverse-menu-complete
  1219.  
  1220. ######################################################################################################################
  1221.  
  1222. ### Functions ###
  1223.  
  1224. ## Git Prompt ##
  1225.  
  1226. function git_prompt_info() {
  1227. local ref
  1228. if [[ "$(command git config --get oh-my-zsh.hide-status 2>/dev/null)" != "1" ]]; then
  1229. ref=$(command git symbolic-ref HEAD 2> /dev/null) || \
  1230. ref=$(command git rev-parse --short HEAD 2> /dev/null) || return 0
  1231. echo "$ZSH_THEME_GIT_PROMPT_PREFIX${ref#refs/heads/}$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_SUFFIX"
  1232. fi
  1233. }
  1234.  
  1235. # Checks if working tree is dirty
  1236. function parse_git_dirty() {
  1237. local STATUS=''
  1238. local -a FLAGS
  1239. FLAGS=('--porcelain')
  1240. if [[ "$(command git config --get oh-my-zsh.hide-dirty)" != "1" ]]; then
  1241. if [[ $POST_1_7_2_GIT -gt 0 ]]; then
  1242. FLAGS+='--ignore-submodules=dirty'
  1243. fi
  1244. if [[ "$DISABLE_UNTRACKED_FILES_DIRTY" == "true" ]]; then
  1245. FLAGS+='--untracked-files=no'
  1246. fi
  1247. STATUS=$(command git status ${FLAGS} 2> /dev/null | tail -n1)
  1248. fi
  1249. if [[ -n $STATUS ]]; then
  1250. echo "$ZSH_THEME_GIT_PROMPT_DIRTY"
  1251. else
  1252. echo "$ZSH_THEME_GIT_PROMPT_CLEAN"
  1253. fi
  1254. }
  1255.  
  1256. # Gets the difference between the local and remote branches
  1257. function git_remote_status() {
  1258. local remote ahead behind git_remote_status git_remote_status_detailed
  1259. remote=${$(command git rev-parse --verify ${hook_com[branch]}@{upstream} --symbolic-full-name 2>/dev/null)/refs\/remotes\/}
  1260. if [[ -n ${remote} ]]; then
  1261. ahead=$(command git rev-list ${hook_com[branch]}@{upstream}..HEAD 2>/dev/null | wc -l)
  1262. behind=$(command git rev-list HEAD..${hook_com[branch]}@{upstream} 2>/dev/null | wc -l)
  1263.  
  1264. if [[ $ahead -eq 0 ]] && [[ $behind -eq 0 ]]; then
  1265. git_remote_status="$ZSH_THEME_GIT_PROMPT_EQUAL_REMOTE"
  1266. elif [[ $ahead -gt 0 ]] && [[ $behind -eq 0 ]]; then
  1267. git_remote_status="$ZSH_THEME_GIT_PROMPT_AHEAD_REMOTE"
  1268. git_remote_status_detailed="$ZSH_THEME_GIT_PROMPT_AHEAD_REMOTE_COLOR$ZSH_THEME_GIT_PROMPT_AHEAD_REMOTE$((ahead))%{$reset_color%}"
  1269. elif [[ $behind -gt 0 ]] && [[ $ahead -eq 0 ]]; then
  1270. git_remote_status="$ZSH_THEME_GIT_PROMPT_BEHIND_REMOTE"
  1271. git_remote_status_detailed="$ZSH_THEME_GIT_PROMPT_BEHIND_REMOTE_COLOR$ZSH_THEME_GIT_PROMPT_BEHIND_REMOTE$((behind))%{$reset_color%}"
  1272. elif [[ $ahead -gt 0 ]] && [[ $behind -gt 0 ]]; then
  1273. git_remote_status="$ZSH_THEME_GIT_PROMPT_DIVERGED_REMOTE"
  1274. git_remote_status_detailed="$ZSH_THEME_GIT_PROMPT_AHEAD_REMOTE_COLOR$ZSH_THEME_GIT_PROMPT_AHEAD_REMOTE$((ahead))%{$reset_color%}$ZSH_THEME_GIT_PROMPT_BEHIND_REMOTE_COLOR$ZSH_THEME_GIT_PROMPT_BEHIND_REMOTE$((behind))%{$reset_color%}"
  1275. fi
  1276.  
  1277. if [[ -n $ZSH_THEME_GIT_PROMPT_REMOTE_STATUS_DETAILED ]]; then
  1278. git_remote_status="$ZSH_THEME_GIT_PROMPT_REMOTE_STATUS_PREFIX$remote$git_remote_status_detailed$ZSH_THEME_GIT_PROMPT_REMOTE_STATUS_SUFFIX"
  1279. fi
  1280.  
  1281. echo $git_remote_status
  1282. fi
  1283. }
  1284.  
  1285. # Outputs the name of the current branch
  1286. # Usage example: git pull origin $(git_current_branch)
  1287. # Using '--quiet' with 'symbolic-ref' will not cause a fatal error (128) if
  1288. # it's not a symbolic ref, but in a Git repo.
  1289. function git_current_branch() {
  1290. local ref
  1291. ref=$(command git symbolic-ref --quiet HEAD 2> /dev/null)
  1292. local ret=$?
  1293. if [[ $ret != 0 ]]; then
  1294. [[ $ret == 128 ]] && return # no git repo.
  1295. ref=$(command git rev-parse --short HEAD 2> /dev/null) || return
  1296. fi
  1297. echo ${ref#refs/heads/}
  1298. }
  1299.  
  1300.  
  1301. # Gets the number of commits ahead from remote
  1302. function git_commits_ahead() {
  1303. if command git rev-parse --git-dir &>/dev/null; then
  1304. local commits="$(git rev-list --count @{upstream}..HEAD 2>/dev/null)"
  1305. if [[ -n "$commits" && "$commits" != 0 ]]; then
  1306. echo "$ZSH_THEME_GIT_COMMITS_AHEAD_PREFIX$commits$ZSH_THEME_GIT_COMMITS_AHEAD_SUFFIX"
  1307. fi
  1308. fi
  1309. }
  1310.  
  1311. # Gets the number of commits behind remote
  1312. function git_commits_behind() {
  1313. if command git rev-parse --git-dir &>/dev/null; then
  1314. local commits="$(git rev-list --count HEAD..@{upstream} 2>/dev/null)"
  1315. if [[ -n "$commits" && "$commits" != 0 ]]; then
  1316. echo "$ZSH_THEME_GIT_COMMITS_BEHIND_PREFIX$commits$ZSH_THEME_GIT_COMMITS_BEHIND_SUFFIX"
  1317. fi
  1318. fi
  1319. }
  1320.  
  1321. # Outputs if current branch is ahead of remote
  1322. function git_prompt_ahead() {
  1323. if [[ -n "$(command git rev-list origin/$(git_current_branch)..HEAD 2> /dev/null)" ]]; then
  1324. echo "$ZSH_THEME_GIT_PROMPT_AHEAD"
  1325. fi
  1326. }
  1327.  
  1328. # Outputs if current branch is behind remote
  1329. function git_prompt_behind() {
  1330. if [[ -n "$(command git rev-list HEAD..origin/$(git_current_branch) 2> /dev/null)" ]]; then
  1331. echo "$ZSH_THEME_GIT_PROMPT_BEHIND"
  1332. fi
  1333. }
  1334.  
  1335. # Outputs if current branch exists on remote or not
  1336. function git_prompt_remote() {
  1337. if [[ -n "$(command git show-ref origin/$(git_current_branch) 2> /dev/null)" ]]; then
  1338. echo "$ZSH_THEME_GIT_PROMPT_REMOTE_EXISTS"
  1339. else
  1340. echo "$ZSH_THEME_GIT_PROMPT_REMOTE_MISSING"
  1341. fi
  1342. }
  1343.  
  1344. # Formats prompt string for current git commit short SHA
  1345. function git_prompt_short_sha() {
  1346. local SHA
  1347. SHA=$(command git rev-parse --short HEAD 2> /dev/null) && echo "$ZSH_THEME_GIT_PROMPT_SHA_BEFORE$SHA$ZSH_THEME_GIT_PROMPT_SHA_AFTER"
  1348. }
  1349.  
  1350. # Formats prompt string for current git commit long SHA
  1351. function git_prompt_long_sha() {
  1352. local SHA
  1353. SHA=$(command git rev-parse HEAD 2> /dev/null) && echo "$ZSH_THEME_GIT_PROMPT_SHA_BEFORE$SHA$ZSH_THEME_GIT_PROMPT_SHA_AFTER"
  1354. }
  1355.  
  1356. # Get the status of the working tree
  1357. function git_prompt_status() {
  1358. local INDEX STATUS
  1359. INDEX=$(command git status --porcelain -b 2> /dev/null)
  1360. STATUS=""
  1361. if $(echo "$INDEX" | command grep -E '^\?\? ' &> /dev/null); then
  1362. STATUS="$ZSH_THEME_GIT_PROMPT_UNTRACKED$STATUS"
  1363. fi
  1364. if $(echo "$INDEX" | grep '^A ' &> /dev/null); then
  1365. STATUS="$ZSH_THEME_GIT_PROMPT_ADDED$STATUS"
  1366. elif $(echo "$INDEX" | grep '^M ' &> /dev/null); then
  1367. STATUS="$ZSH_THEME_GIT_PROMPT_ADDED$STATUS"
  1368. elif $(echo "$INDEX" | grep '^MM ' &> /dev/null); then
  1369. STATUS="$ZSH_THEME_GIT_PROMPT_ADDED$STATUS"
  1370. fi
  1371. if $(echo "$INDEX" | grep '^ M ' &> /dev/null); then
  1372. STATUS="$ZSH_THEME_GIT_PROMPT_MODIFIED$STATUS"
  1373. elif $(echo "$INDEX" | grep '^AM ' &> /dev/null); then
  1374. STATUS="$ZSH_THEME_GIT_PROMPT_MODIFIED$STATUS"
  1375. elif $(echo "$INDEX" | grep '^MM ' &> /dev/null); then
  1376. STATUS="$ZSH_THEME_GIT_PROMPT_MODIFIED$STATUS"
  1377. elif $(echo "$INDEX" | grep '^ T ' &> /dev/null); then
  1378. STATUS="$ZSH_THEME_GIT_PROMPT_MODIFIED$STATUS"
  1379. fi
  1380. if $(echo "$INDEX" | grep '^R ' &> /dev/null); then
  1381. STATUS="$ZSH_THEME_GIT_PROMPT_RENAMED$STATUS"
  1382. fi
  1383. if $(echo "$INDEX" | grep '^ D ' &> /dev/null); then
  1384. STATUS="$ZSH_THEME_GIT_PROMPT_DELETED$STATUS"
  1385. elif $(echo "$INDEX" | grep '^D ' &> /dev/null); then
  1386. STATUS="$ZSH_THEME_GIT_PROMPT_DELETED$STATUS"
  1387. elif $(echo "$INDEX" | grep '^AD ' &> /dev/null); then
  1388. STATUS="$ZSH_THEME_GIT_PROMPT_DELETED$STATUS"
  1389. fi
  1390. if $(command git rev-parse --verify refs/stash >/dev/null 2>&1); then
  1391. STATUS="$ZSH_THEME_GIT_PROMPT_STASHED$STATUS"
  1392. fi
  1393. if $(echo "$INDEX" | grep '^UU ' &> /dev/null); then
  1394. STATUS="$ZSH_THEME_GIT_PROMPT_UNMERGED$STATUS"
  1395. fi
  1396. if $(echo "$INDEX" | grep '^## [^ ]\+ .*ahead' &> /dev/null); then
  1397. STATUS="$ZSH_THEME_GIT_PROMPT_AHEAD$STATUS"
  1398. fi
  1399. if $(echo "$INDEX" | grep '^## [^ ]\+ .*behind' &> /dev/null); then
  1400. STATUS="$ZSH_THEME_GIT_PROMPT_BEHIND$STATUS"
  1401. fi
  1402. if $(echo "$INDEX" | grep '^## [^ ]\+ .*diverged' &> /dev/null); then
  1403. STATUS="$ZSH_THEME_GIT_PROMPT_DIVERGED$STATUS"
  1404. fi
  1405. echo $STATUS
  1406. }
  1407.  
  1408. # Compares the provided version of git to the version installed and on path
  1409. # Outputs -1, 0, or 1 if the installed version is less than, equal to, or
  1410. # greater than the input version, respectively.
  1411. function git_compare_version() {
  1412. local INPUT_GIT_VERSION INSTALLED_GIT_VERSION i
  1413. INPUT_GIT_VERSION=(${(s/./)1})
  1414. INSTALLED_GIT_VERSION=($(command git --version 2>/dev/null))
  1415. INSTALLED_GIT_VERSION=(${(s/./)INSTALLED_GIT_VERSION[3]})
  1416.  
  1417. for i in {1..3}; do
  1418. if [[ $INSTALLED_GIT_VERSION[$i] -gt $INPUT_GIT_VERSION[$i] ]]; then
  1419. echo 1
  1420. return 0
  1421. fi
  1422. if [[ $INSTALLED_GIT_VERSION[$i] -lt $INPUT_GIT_VERSION[$i] ]]; then
  1423. echo -1
  1424. return 0
  1425. fi
  1426. done
  1427. echo 0
  1428. }
  1429.  
  1430. # Outputs the name of the current user
  1431. # Usage example: $(git_current_user_name)
  1432. function git_current_user_name() {
  1433. command git config user.name 2>/dev/null
  1434. }
  1435.  
  1436. # Outputs the email of the current user
  1437. # Usage example: $(git_current_user_email)
  1438. function git_current_user_email() {
  1439. command git config user.email 2>/dev/null
  1440. }
  1441.  
  1442. # This is unlikely to change so make it all statically assigned
  1443. POST_1_7_2_GIT=$(git_compare_version "1.7.2")
  1444. # Clean up the namespace slightly by removing the checker function
  1445. unfunction git_compare_version
  1446.  
  1447. #====================================================================================================================#
  1448.  
  1449. ## Syntax Highlighting ##
  1450.  
  1451. typeset -gA __fast_highlight_main__command_type_cache FAST_BLIST_PATTERNS
  1452. typeset -g FAST_WORK_DIR
  1453. : ${FAST_WORK_DIR:=$FAST_BASE_DIR}
  1454. FAST_WORK_DIR=${~FAST_WORK_DIR}
  1455. () {
  1456. setopt localoptions extendedglob
  1457. local -A map
  1458. map=( "XDG:" "${XDG_CONFIG_HOME:-$HOME/.config}/fsh/"
  1459. "LOCAL:" "/usr/local/share/fsh/"
  1460. "HOME:" "$HOME/.fsh/"
  1461. "OPT:" "/opt/local/share/fsh/"
  1462. )
  1463. FAST_WORK_DIR=${${FAST_WORK_DIR/(#m)(#s)(XDG|LOCAL|HOME|OPT):(#c0,1)/${map[${MATCH%:}:]}}%/}
  1464. }
  1465.  
  1466. # Define default styles. You can set this after loading the plugin in
  1467. # Zshrc and use 256 colors via numbers, like: fg=150
  1468. typeset -gA FAST_HIGHLIGHT_STYLES
  1469. if [[ -e $FAST_WORK_DIR/current_theme.zsh ]]; then
  1470. source $FAST_WORK_DIR/current_theme.zsh
  1471. else
  1472. # built-in theme
  1473. zstyle :plugin:fast-syntax-highlighting theme default
  1474. : ${FAST_HIGHLIGHT_STYLES[default]:=none}
  1475. : ${FAST_HIGHLIGHT_STYLES[unknown-token]:=fg=red,bold}
  1476. : ${FAST_HIGHLIGHT_STYLES[reserved-word]:=fg=yellow}
  1477. : ${FAST_HIGHLIGHT_STYLES[subcommand]:=fg=yellow}
  1478. : ${FAST_HIGHLIGHT_STYLES[alias]:=fg=green}
  1479. : ${FAST_HIGHLIGHT_STYLES[suffix-alias]:=fg=green}
  1480. : ${FAST_HIGHLIGHT_STYLES[global-alias]:=bg=blue}
  1481. : ${FAST_HIGHLIGHT_STYLES[builtin]:=fg=green}
  1482. : ${FAST_HIGHLIGHT_STYLES[function]:=fg=green}
  1483. : ${FAST_HIGHLIGHT_STYLES[command]:=fg=green}
  1484. : ${FAST_HIGHLIGHT_STYLES[precommand]:=fg=green}
  1485. : ${FAST_HIGHLIGHT_STYLES[commandseparator]:=none}
  1486. : ${FAST_HIGHLIGHT_STYLES[hashed-command]:=fg=green}
  1487. : ${FAST_HIGHLIGHT_STYLES[path]:=fg=magenta}
  1488. : ${FAST_HIGHLIGHT_STYLES[path-to-dir]:=fg=magenta,underline}
  1489. : ${FAST_HIGHLIGHT_STYLES[path_pathseparator]:=}
  1490. : ${FAST_HIGHLIGHT_STYLES[globbing]:=fg=blue,bold}
  1491. : ${FAST_HIGHLIGHT_STYLES[globbing-ext]:=fg=blue,bold}
  1492. : ${FAST_HIGHLIGHT_STYLES[history-expansion]:=fg=blue,bold}
  1493. : ${FAST_HIGHLIGHT_STYLES[single-hyphen-option]:=fg=cyan}
  1494. : ${FAST_HIGHLIGHT_STYLES[double-hyphen-option]:=fg=cyan}
  1495. : ${FAST_HIGHLIGHT_STYLES[back-quoted-argument]:=none}
  1496. : ${FAST_HIGHLIGHT_STYLES[single-quoted-argument]:=fg=yellow}
  1497. : ${FAST_HIGHLIGHT_STYLES[double-quoted-argument]:=fg=yellow}
  1498. : ${FAST_HIGHLIGHT_STYLES[dollar-quoted-argument]:=fg=yellow}
  1499. : ${FAST_HIGHLIGHT_STYLES[back-or-dollar-double-quoted-argument]:=fg=cyan}
  1500. : ${FAST_HIGHLIGHT_STYLES[back-dollar-quoted-argument]:=fg=cyan}
  1501. : ${FAST_HIGHLIGHT_STYLES[assign]:=none}
  1502. : ${FAST_HIGHLIGHT_STYLES[redirection]:=none}
  1503. : ${FAST_HIGHLIGHT_STYLES[comment]:=fg=black,bold}
  1504. : ${FAST_HIGHLIGHT_STYLES[variable]:=fg=113}
  1505. : ${FAST_HIGHLIGHT_STYLES[mathvar]:=fg=blue,bold}
  1506. : ${FAST_HIGHLIGHT_STYLES[mathnum]:=fg=magenta}
  1507. : ${FAST_HIGHLIGHT_STYLES[matherr]:=fg=red}
  1508. : ${FAST_HIGHLIGHT_STYLES[assign-array-bracket]:=fg=green}
  1509. : ${FAST_HIGHLIGHT_STYLES[for-loop-variable]:=none}
  1510. : ${FAST_HIGHLIGHT_STYLES[for-loop-operator]:=fg=yellow}
  1511. : ${FAST_HIGHLIGHT_STYLES[for-loop-number]:=fg=magenta}
  1512. : ${FAST_HIGHLIGHT_STYLES[for-loop-separator]:=fg=yellow,bold}
  1513. : ${FAST_HIGHLIGHT_STYLES[here-string-tri]:=fg=yellow}
  1514. : ${FAST_HIGHLIGHT_STYLES[here-string-text]:=bg=blue}
  1515. : ${FAST_HIGHLIGHT_STYLES[here-string-var]:=fg=cyan,bg=blue}
  1516. : ${FAST_HIGHLIGHT_STYLES[case-input]:=fg=green}
  1517. : ${FAST_HIGHLIGHT_STYLES[case-parentheses]:=fg=yellow}
  1518. : ${FAST_HIGHLIGHT_STYLES[case-condition]:=bg=blue}
  1519. : ${FAST_HIGHLIGHT_STYLES[paired-bracket]:=bg=blue}
  1520. : ${FAST_HIGHLIGHT_STYLES[bracket-level-1]:=fg=green,bold}
  1521. : ${FAST_HIGHLIGHT_STYLES[bracket-level-2]:=fg=yellow,bold}
  1522. : ${FAST_HIGHLIGHT_STYLES[bracket-level-3]:=fg=cyan,bold}
  1523. : ${FAST_HIGHLIGHT_STYLES[single-sq-bracket]:=fg=green}
  1524. : ${FAST_HIGHLIGHT_STYLES[double-sq-bracket]:=fg=green}
  1525. : ${FAST_HIGHLIGHT_STYLES[double-paren]:=fg=yellow}
  1526. fi
  1527.  
  1528. # This can overwrite some of *_STYLES fields
  1529. [[ -r $FAST_WORK_DIR/theme_overlay.zsh ]] && source $FAST_WORK_DIR/theme_overlay.zsh
  1530.  
  1531. typeset -gA __FAST_HIGHLIGHT_TOKEN_TYPES
  1532.  
  1533. __FAST_HIGHLIGHT_TOKEN_TYPES=(
  1534.  
  1535. # Precommand
  1536.  
  1537. 'builtin' 1
  1538. 'command' 1
  1539. 'exec' 1
  1540. 'nocorrect' 1
  1541. 'noglob' 1
  1542. 'pkexec' 1 # immune to #121 because it's usually not passed --option flags
  1543.  
  1544. # Control flow
  1545. # Tokens that, at (naively-determined) "command position", are followed by
  1546. # a de jure command position. All of these are reserved words.
  1547.  
  1548. $'\x7b' 2 # block '{'
  1549. $'\x28' 2 # subshell '('
  1550. '()' 2 # anonymous function
  1551. 'while' 2
  1552. 'until' 2
  1553. 'if' 2
  1554. 'then' 2
  1555. 'elif' 2
  1556. 'else' 2
  1557. 'do' 2
  1558. 'time' 2
  1559. 'coproc' 2
  1560. '!' 2 # reserved word; unrelated to $histchars[1]
  1561.  
  1562. # Command separators
  1563.  
  1564. '|' 3
  1565. '||' 3
  1566. ';' 3
  1567. '&' 3
  1568. '&&' 3
  1569. '|&' 3
  1570. '&!' 3
  1571. '&|' 3
  1572. # ### 'case' syntax, but followed by a pattern, not by a command
  1573. # ';;' ';&' ';|'
  1574. )
  1575.  
  1576. # A hash instead of multiple globals
  1577. typeset -gA FAST_HIGHLIGHT
  1578.  
  1579. # Brackets highlighter active by default
  1580. : ${FAST_HIGHLIGHT[use_brackets]:=1}
  1581.  
  1582. FAST_HIGHLIGHT+=(
  1583. chroma-fast-theme chroma/-fast-theme.ch
  1584. chroma-alias chroma/-alias.ch
  1585. chroma-autoload chroma/-autoload.ch
  1586. chroma-autorandr chroma/-autorandr.ch
  1587. chroma-docker chroma/-docker.ch
  1588. chroma-example chroma/-example.ch
  1589. chroma-make chroma/-make.ch
  1590. chroma-nmcli chroma/-nmcli.ch
  1591. chroma-node chroma/-node.ch
  1592. chroma-perl chroma/-perl.ch
  1593. chroma-printf chroma/-printf.ch
  1594. chroma-ruby chroma/-ruby.ch
  1595. chroma-scp chroma/-scp.ch
  1596. chroma-ssh chroma/-ssh.ch
  1597.  
  1598. chroma-git chroma/-git.ch
  1599. chroma-hub chroma/-git.ch
  1600. chroma-lab chroma/-git.ch
  1601.  
  1602. chroma-egrep chroma/-grep.ch
  1603. chroma-fgrep chroma/-grep.ch
  1604. chroma-grep chroma/-grep.ch
  1605.  
  1606. chroma-awk chroma/-awk.ch
  1607. chroma-gawk chroma/-awk.ch
  1608. chroma-mawk chroma/-awk.ch
  1609.  
  1610. chroma-source chroma/-source.ch
  1611. chroma-. chroma/-source.ch
  1612.  
  1613. chroma-bash chroma/-sh.ch
  1614. chroma-fish chroma/-sh.ch
  1615. chroma-sh chroma/-sh.ch
  1616. chroma-tmux chroma/-sh.ch
  1617. chroma-zsh chroma/-sh.ch
  1618.  
  1619. chroma-whatis chroma/-whatis.ch
  1620. chroma-man chroma/-whatis.ch
  1621.  
  1622. chroma-hg chroma/-subcommand.ch
  1623. chroma-cvs chroma/-subcommand.ch
  1624. chroma-pip chroma/-subcommand.ch
  1625. chroma-pip2 chroma/-subcommand.ch
  1626. chroma-pip3 chroma/-subcommand.ch
  1627. chroma-gem chroma/-subcommand.ch
  1628. chroma-yard chroma/-subcommand.ch
  1629. chroma-cabal chroma/-subcommand.ch
  1630. chroma-npm chroma/-subcommand.ch
  1631. chroma-nvm chroma/-subcommand.ch
  1632. chroma-yarn chroma/-subcommand.ch
  1633. chroma-brew chroma/-subcommand.ch
  1634. chroma-port chroma/-subcommand.ch
  1635. chroma-yum chroma/-subcommand.ch
  1636. chroma-dnf chroma/-subcommand.ch
  1637. chroma-apt-get chroma/-subcommand.ch
  1638. chroma-apt-cache chroma/-subcommand.ch
  1639. chroma-aptitude chroma/-subcommand.ch
  1640. chroma-keyctl chroma/-subcommand.ch
  1641. chroma-systemctl chroma/-subcommand.ch
  1642. chroma-asciinema chroma/-subcommand.ch
  1643. chroma-ipfs chroma/-subcommand.ch
  1644. chroma-zplugin chroma/-subcommand.ch
  1645. chroma-aspell chroma/-subcommand.ch
  1646. chroma-bspc chroma/-subcommand.ch
  1647. chroma-cryptsetup chroma/-subcommand.ch
  1648. chroma-diskutil chroma/-subcommand.ch
  1649. chroma-exercism chroma/-subcommand.ch
  1650. chroma-gulp chroma/-subcommand.ch
  1651. chroma-i3-msg chroma/-subcommand.ch
  1652. chroma-openssl chroma/-subcommand.ch
  1653. chroma-solargraph chroma/-subcommand.ch
  1654. chroma-subliminal chroma/-subcommand.ch
  1655. chroma-svnadmin chroma/-subcommand.ch
  1656. chroma-travis chroma/-subcommand.ch
  1657. chroma-xdotool chroma/-subcommand.ch
  1658. chroma-zmanage chroma/-subcommand.ch
  1659. chroma-zsystem chroma/-subcommand.ch
  1660. chroma-zypper chroma/-subcommand.ch
  1661.  
  1662. chroma-fpath+=\( chroma/-fpath_peq.ch
  1663. chroma-fpath=\( chroma/-fpath_peq.ch
  1664. chroma-FPATH+= chroma/-fpath_peq.ch
  1665. chroma-FPATH= chroma/-fpath_peq.ch
  1666. #chroma-which chroma/-which.ch
  1667. #chroma-vim chroma/-vim.ch
  1668. )
  1669.  
  1670. # Assignments seen, to know if math parameter exists
  1671. typeset -gA FAST_ASSIGNS_SEEN
  1672.  
  1673. # Exposing tokens found on command position,
  1674. # for other scripts to process
  1675. typeset -ga ZLAST_COMMANDS
  1676.  
  1677. # Get the type of a command.
  1678. #
  1679. # Uses the zsh/parameter module if available to avoid forks, and a
  1680. # wrapper around 'type -w' as fallback.
  1681. #
  1682. # Takes a single argument.
  1683. #
  1684. # The result will be stored in REPLY.
  1685. -fast-highlight-main-type() {
  1686. REPLY=$__fast_highlight_main__command_type_cache[(e)$1]
  1687. [[ -z $REPLY ]] && {
  1688.  
  1689. if zmodload -e zsh/parameter; then
  1690. if (( $+aliases[(e)$1] )); then
  1691. REPLY=alias
  1692. elif (( ${+galiases[(e)$1]} )); then
  1693. REPLY="global alias"
  1694. elif (( $+functions[(e)$1] )); then
  1695. REPLY=function
  1696. elif (( $+builtins[(e)$1] )); then
  1697. REPLY=builtin
  1698. elif (( $+commands[(e)$1] )); then
  1699. REPLY=command
  1700. elif (( $+saliases[(e)${1##*.}] )); then
  1701. REPLY='suffix alias'
  1702. elif (( $reswords[(Ie)$1] )); then
  1703. REPLY=reserved
  1704. # zsh 5.2 and older have a bug whereby running 'type -w ./sudo' implicitly
  1705. # runs 'hash ./sudo=/usr/local/bin/./sudo' (assuming /usr/local/bin/sudo
  1706. # exists and is in $PATH). Avoid triggering the bug, at the expense of
  1707. # falling through to the $() below, incurring a fork. (Issue #354.)
  1708. #
  1709. # The second disjunct mimics the isrelative() C call from the zsh bug.
  1710. elif [[ $1 != */* || ${+ZSH_ARGZERO} = "1" ]] && ! builtin type -w -- $1 >/dev/null 2>&1; then
  1711. REPLY=none
  1712. fi
  1713. fi
  1714.  
  1715. [[ -z $REPLY ]] && REPLY="${$(LC_ALL=C builtin type -w -- $1 2>/dev/null)##*: }"
  1716.  
  1717. [[ $REPLY = "none" ]] && {
  1718. [[ -n ${FAST_BLIST_PATTERNS[(k)${${(M)1:#/*}:-$PWD/$1}]} ]] || {
  1719. [[ -d $1 ]] && REPLY="dirpath" || {
  1720. for cdpath_dir in $cdpath; do
  1721. [[ -d $cdpath_dir/$1 ]] && { REPLY="dirpath"; break; }
  1722. done
  1723. }
  1724. }
  1725. }
  1726.  
  1727. __fast_highlight_main__command_type_cache[(e)$1]=$REPLY
  1728.  
  1729. }
  1730. }
  1731.  
  1732. # Below are variables that must be defined in outer
  1733. # scope so that they are reachable in *-process()
  1734. -fast-highlight-fill-option-variables() {
  1735. if [[ -o ignore_braces ]] || eval '[[ -o ignore_close_braces ]] 2>/dev/null'; then
  1736. FAST_HIGHLIGHT[right_brace_is_recognised_everywhere]=0
  1737. else
  1738. FAST_HIGHLIGHT[right_brace_is_recognised_everywhere]=1
  1739. fi
  1740.  
  1741. if [[ -o path_dirs ]]; then
  1742. FAST_HIGHLIGHT[path_dirs_was_set]=1
  1743. else
  1744. FAST_HIGHLIGHT[path_dirs_was_set]=0
  1745. fi
  1746.  
  1747. if [[ -o multi_func_def ]]; then
  1748. FAST_HIGHLIGHT[multi_func_def]=1
  1749. else
  1750. FAST_HIGHLIGHT[multi_func_def]=0
  1751. fi
  1752.  
  1753. if [[ -o interactive_comments ]]; then
  1754. FAST_HIGHLIGHT[ointeractive_comments]=1
  1755. else
  1756. FAST_HIGHLIGHT[ointeractive_comments]=0
  1757. fi
  1758. }
  1759.  
  1760. # Main syntax highlighting function.
  1761. -fast-highlight-process()
  1762. {
  1763. emulate -L zsh
  1764. setopt extendedglob bareglobqual nonomatch noksharrays
  1765.  
  1766. [[ $CONTEXT == "select" ]] && return 0
  1767.  
  1768. (( FAST_HIGHLIGHT[path_dirs_was_set] )) && setopt PATH_DIRS
  1769. (( FAST_HIGHLIGHT[ointeractive_comments] )) && local interactive_comments= # _set_ to empty
  1770.  
  1771. # Variable declarations and initializations
  1772. # in_array_assignment true between 'a=(' and the matching ')'
  1773. # braces_stack: "R" for round, "Q" for square, "Y" for curly
  1774. # _mybuf, cdpath_dir are used in sub-functions
  1775. local _start_pos=$3 _end_pos __start __end highlight_glob=1 __arg __style in_array_assignment=0 MATCH expanded_path braces_stack __buf=$1$2 _mybuf __workbuf cdpath_dir active_command alias_target _was_double_hyphen=0 __nul=$'\0' __tmp
  1776. # __arg_type can be 0, 1, 2 or 3, i.e. precommand, control flow, command separator
  1777. # __idx and _end_idx are used in sub-functions
  1778. # for this_word and next_word look below at commented integers and at state machine description
  1779. integer __arg_type=0 MBEGIN MEND in_redirection __len=${#__buf} __PBUFLEN=${#1} already_added offset __idx _end_idx this_word=1 next_word=0 __pos __asize __delimited=0 itmp iitmp
  1780. local -a match mbegin mend __inputs __list
  1781.  
  1782. # This comment explains the numbers:
  1783. # BIT_for - word after reserved-word-recognized `for'
  1784. # BIT_afpcmd - word after a precommand that can take options, like `command' and `exec'
  1785. # integer BIT_start=1 BIT_regular=2 BIT_sudo_opt=4 BIT_sudo_arg=8 BIT_always=16 BIT_for=32 BIT_afpcmd=64
  1786. # integer BIT_chroma=8192
  1787.  
  1788. integer BIT_case_preamble=512 BIT_case_item=1024 BIT_case_nempty_item=2048 BIT_case_code=4096
  1789.  
  1790. # Braces stack
  1791. # T - typeset, local, etc.
  1792.  
  1793. # State machine
  1794. #
  1795. # The states are:
  1796. # - :__start: Command word
  1797. # - :sudo_opt: A leading-dash option to sudo (such as "-u" or "-i")
  1798. # - :sudo_arg: The argument to a sudo leading-dash option that takes one,
  1799. # when given as a separate word; i.e., "foo" in "-u foo" (two
  1800. # words) but not in "-ufoo" (one word).
  1801. # - :regular: "Not a command word", and command delimiters are permitted.
  1802. # Mainly used to detect premature termination of commands.
  1803. # - :always: The word 'always' in the «{ foo } always { bar }» syntax.
  1804. #
  1805. # When the kind of a word is not yet known, $this_word / $next_word may contain
  1806. # multiple states. For example, after "sudo -i", the next word may be either
  1807. # another --flag or a command name, hence the state would include both :__start:
  1808. # and :sudo_opt:.
  1809. #
  1810. # The tokens are always added with both leading and trailing colons to serve as
  1811. # word delimiters (an improvised array); [[ $x == *:foo:* ]] and x=${x//:foo:/}
  1812. # will DTRT regardless of how many elements or repetitions $x has..
  1813. #
  1814. # Handling of redirections: upon seeing a redirection token, we must stall
  1815. # the current state --- that is, the value of $this_word --- for two iterations
  1816. # (one for the redirection operator, one for the word following it representing
  1817. # the redirection target). Therefore, we set $in_redirection to 2 upon seeing a
  1818. # redirection operator, decrement it each iteration, and stall the current state
  1819. # when it is non-zero. Thus, upon reaching the next word (the one that follows
  1820. # the redirection operator and target), $this_word will still contain values
  1821. # appropriate for the word immediately following the word that preceded the
  1822. # redirection operator.
  1823. #
  1824. # The "the previous word was a redirection operator" state is not communicated
  1825. # to the next iteration via $next_word/$this_word as usual, but via
  1826. # $in_redirection. The value of $next_word from the iteration that processed
  1827. # the operator is discarded.
  1828. #
  1829.  
  1830. # Command exposure for other scripts
  1831. ZLAST_COMMANDS=()
  1832. # Restart observing of assigns
  1833. FAST_ASSIGNS_SEEN=()
  1834. # Restart function's gathering
  1835. FAST_HIGHLIGHT[chroma-autoload-elements]=""
  1836. # Restart FPATH elements gathering
  1837. FAST_HIGHLIGHT[chroma-fpath_peq-elements]=""
  1838.  
  1839. [[ -n $ZCALC_ACTIVE ]] && {
  1840. _start_pos=0; _end_pos=__len; __arg=$__buf
  1841. -fast-highlight-math-string
  1842. return 0
  1843. }
  1844.  
  1845. # Processing buffer
  1846. local proc_buf=$__buf needle
  1847. for __arg in ${interactive_comments-${(z)__buf}} \
  1848. ${interactive_comments+${(zZ+c+)__buf}}; do
  1849.  
  1850. # Initialize $next_word to its default value?
  1851. (( in_redirection = in_redirection > 0 ? in_redirection - 1 : in_redirection ));
  1852. (( next_word = (in_redirection == 0) ? 2 : next_word )) # else Stall $next_word.
  1853. (( next_word = next_word | (this_word & (BIT_case_code|8192)) ))
  1854.  
  1855. # If we have a good delimiting construct just ending, and '{'
  1856. # occurs, then respect this and go for alternate syntax, i.e.
  1857. # treat '{' (\x7b) as if it's on command position
  1858. [[ $__arg = '{' && $__delimited = 2 ]] && { (( this_word = (this_word & ~2) | 1 )); __delimited=0; }
  1859.  
  1860. __asize=${#__arg}
  1861.  
  1862. # Reset state of working variables
  1863. already_added=0
  1864. __style=${FAST_THEME_NAME}unknown-token
  1865. (( this_word & 1 )) && { in_array_assignment=0; [[ $__arg == 'noglob' ]] && highlight_glob=0; }
  1866.  
  1867. # Compute the new $_start_pos and $_end_pos, skipping over whitespace in $__buf.
  1868. if [[ $__arg == ';' ]] ; then
  1869. braces_stack=${braces_stack#T}
  1870. __delimited=0
  1871.  
  1872. # Both ; and \n are rendered as a ";" (SEPER) by the ${(z)..} flag.
  1873. needle=$';\n'
  1874. [[ $proc_buf = (#b)[^$needle]#([$needle]##)* ]] && offset=${mbegin[1]}-1
  1875. (( _start_pos += offset ))
  1876. (( _end_pos = _start_pos + __asize ))
  1877.  
  1878. # Prepare next loop cycle
  1879. (( this_word & BIT_case_item )) || { (( in_array_assignment )) && (( this_word = 2 | (this_word & BIT_case_code) )) || { (( this_word = 1 | (this_word & BIT_case_code) )); highlight_glob=1; }; }
  1880. in_redirection=0
  1881.  
  1882. # Chance to highlight ';'
  1883. [[ ${proc_buf[offset+1]} != $'\n' ]] && {
  1884. [[ ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}commandseparator]} != "none" ]] && \
  1885. (( __start=_start_pos-__PBUFLEN, __end=_end_pos-__PBUFLEN, __start >= 0 )) && \
  1886. reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}commandseparator]}")
  1887. }
  1888.  
  1889. proc_buf=${proc_buf[offset + __asize + 1,__len]}
  1890. _start_pos=$_end_pos
  1891. continue
  1892. else
  1893. offset=0
  1894. if [[ $proc_buf = (#b)(#s)(([[:space:]]|\\[[:space:]])##)* ]]; then
  1895. # The first, outer parenthesis
  1896. offset=${mend[1]}
  1897. fi
  1898. (( _start_pos += offset ))
  1899. (( _end_pos = _start_pos + __asize ))
  1900.  
  1901. # No-hit will result in value 0
  1902. __arg_type=${__FAST_HIGHLIGHT_TOKEN_TYPES[$__arg]}
  1903. fi
  1904.  
  1905. (( this_word & 1 )) && ZLAST_COMMANDS+=( $__arg );
  1906.  
  1907. proc_buf=${proc_buf[offset + __asize + 1,__len]}
  1908.  
  1909. # Handle the INTERACTIVE_COMMENTS option.
  1910. #
  1911. # We use the (Z+c+) flag so the entire comment is presented as one token in $__arg.
  1912. if [[ -n ${interactive_comments+'set'} && $__arg == ${histchars[3]}* ]]; then
  1913. if (( this_word & 3 )); then
  1914. __style=${FAST_THEME_NAME}comment
  1915. else
  1916. __style=${FAST_THEME_NAME}unknown-token # prematurely terminated
  1917. fi
  1918. # ADD
  1919. (( __start=_start_pos-__PBUFLEN, __end=_end_pos-__PBUFLEN, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}")
  1920. _start_pos=$_end_pos
  1921. continue
  1922. fi
  1923.  
  1924. # Redirection?
  1925. [[ $__arg == (<0-9>|)(\<|\>)* && $__arg != (\<|\>)$'\x28'* && $__arg != "<<<" ]] && \
  1926. in_redirection=2
  1927.  
  1928. # Special-case the first word after 'sudo'.
  1929. if (( ! in_redirection )); then
  1930. (( this_word & 4 )) && [[ $__arg != -* ]] && (( this_word = this_word ^ 4 ))
  1931.  
  1932. # Parse the sudo command line
  1933. if (( this_word & 4 )); then
  1934. case $__arg in
  1935. # Flag that requires an argument
  1936. '-'[Cgprtu])
  1937. (( this_word = this_word & ~1 ))
  1938. (( next_word = 8 | (this_word & BIT_case_code) ))
  1939. ;;
  1940. # This prevents misbehavior with sudo -u -otherargument
  1941. '-'*)
  1942. (( this_word = this_word & ~1 ))
  1943. (( next_word = next_word | 1 | 4 ))
  1944. ;;
  1945. esac
  1946. elif (( this_word & 8 )); then
  1947. (( next_word = next_word | 4 | 1 ))
  1948. elif (( this_word & 64 )); then
  1949. [[ $__arg = -[pvV-]## && $active_command = "command" ]] && (( this_word = (this_word & ~1) | 2, next_word = (next_word | 65) & ~2 ))
  1950. [[ $__arg = -[cla-]## && $active_command = "exec" ]] && (( this_word = (this_word & ~1) | 2, next_word = (next_word | 65) & ~2 ))
  1951. [[ $__arg = \{[a-zA-Z][a-zA-Z0-9]#\} && $active_command = "exec" ]] && {
  1952. # Highlight {descriptor} passed to exec
  1953. (( this_word = (this_word & ~1) | 2, next_word = (next_word | 65) & ~2 ))
  1954. (( __start=_start_pos-__PBUFLEN, __end=_end_pos-__PBUFLEN, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}exec-descriptor]}")
  1955. already_added=1
  1956. }
  1957. fi
  1958. fi
  1959.  
  1960. (( this_word & 1 )) && {
  1961. # !in_redirection needed particularly for exec {A}>b {C}>d
  1962. (( !in_redirection )) && active_command=$__arg
  1963. _mybuf=${${aliases[$active_command]:-$active_command}##[[:space:]]#(command|builtin|exec|noglob|nocorrect|pkexec)[[:space:]]#}
  1964. [[ "$_mybuf" = (#b)(FPATH+(#c0,1)=)* ]] && _mybuf="${match[1]} ${(j: :)${(s,:,)${_mybuf#FPATH+(#c0,1)=}}}"
  1965. [[ -n ${FAST_HIGHLIGHT[chroma-${_mybuf%% *}]} ]] && {
  1966. __list=( ${(z@)_mybuf} )
  1967. if (( ${#__list} > 1 )) || [[ $active_command != $_mybuf ]]; then
  1968. __style=${FAST_THEME_NAME}alias
  1969. (( __start=_start_pos-__PBUFLEN, __end=_end_pos-__PBUFLEN, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}")
  1970.  
  1971. ${FAST_HIGHLIGHT[chroma-${__list[1]}]} 1 "${__list[1]}" "-100000" $_end_pos 2>/dev/null || \
  1972. (( this_word = next_word, next_word = 2 ))
  1973.  
  1974. for _mybuf in "${(@)__list[2,-1]}"; do
  1975. (( next_word = next_word | (this_word & (BIT_case_code|8192)) ))
  1976. ${FAST_HIGHLIGHT[chroma-${__list[1]}]} 0 "$_mybuf" "-100000" $_end_pos 2>/dev/null || \
  1977. (( this_word = next_word, next_word = 2 ))
  1978. done
  1979.  
  1980. # This might have been done multiple times in chroma, but
  1981. # as _end_pos doesn't change, it can be done one more time
  1982. _start_pos=$_end_pos
  1983.  
  1984. continue
  1985. else
  1986. ${FAST_HIGHLIGHT[chroma-$active_command]} 1 "$__arg" $_start_pos $_end_pos 2>/dev/null && continue
  1987. fi
  1988. } || (( 1 ))
  1989. } || {
  1990. (( this_word & 8192 )) && {
  1991. __list=( ${(z@)${aliases[$active_command]:-$active_command}##[[:space:]]#(command|builtin|exec|noglob|nocorrect|pkexec)[[:space:]]#} )
  1992. ${FAST_HIGHLIGHT[chroma-${__list[1]}]} 0 "$__arg" $_start_pos $_end_pos 2>/dev/null && continue
  1993. }
  1994. }
  1995.  
  1996. expanded_path=""
  1997.  
  1998. # The Great Fork: is this a command word? Is this a non-command word?
  1999. if (( this_word & 16 )) && [[ $__arg == 'always' ]]; then
  2000. # try-always construct
  2001. __style=${FAST_THEME_NAME}reserved-word # de facto a reserved word, although not de jure
  2002. (( next_word = 1 | (this_word & BIT_case_code) ))
  2003. elif (( (this_word & 1) && (in_redirection == 0) )) || [[ $braces_stack = T* ]]; then
  2004. if (( __arg_type == 1 )); then
  2005. __style=${FAST_THEME_NAME}precommand
  2006. [[ $__arg = "command" || $__arg = "exec" ]] && (( next_word = next_word | 64 ))
  2007. elif [[ $__arg = "sudo" ]]; then
  2008. __style=${FAST_THEME_NAME}precommand
  2009. (( next_word = (next_word & ~2) | 4 | 1 ))
  2010. else
  2011. _mybuf=${${(Q)__arg}#\"}
  2012. if [[ $_mybuf == \$* ]] && (( ${+parameters} )) && \
  2013. [[ $_mybuf = (#b)\$([a-zA-Z_][a-zA-Z0-9_]#|[0-9]##)(/*|) || $_mybuf = (#b)\$\{([a-zA-Z_][a-zA-Z0-9_]#|[0-9]##)\}(/*|) ]] && \
  2014. (( ${+parameters[${match[1]}]} )); then
  2015. -fast-highlight-main-type ${(P)match[1]}${match[2]}
  2016. elif [[ $braces_stack = T* ]]; then # T - typedef, etc.
  2017. REPLY=none
  2018. else
  2019. : ${expanded_path::=${~_mybuf}}
  2020. -fast-highlight-main-type $expanded_path
  2021. fi
  2022.  
  2023. case $REPLY in
  2024. reserved) # reserved word
  2025. [[ $__arg = "[[" ]] && __style=${FAST_THEME_NAME}double-sq-bracket || __style=${FAST_THEME_NAME}reserved-word
  2026. if [[ $__arg == $'\x7b' ]]; then # '{'
  2027. braces_stack='Y'$braces_stack
  2028. elif [[ $__arg == $'\x7d' && $braces_stack = Y* ]]; then # '}'
  2029. # We're at command word, so no need to check right_brace_is_recognised_everywhere
  2030. braces_stack=${braces_stack#Y}
  2031. __style=${FAST_THEME_NAME}reserved-word
  2032. (( next_word = next_word | 16 ))
  2033. elif [[ $__arg == "[[" ]]; then
  2034. braces_stack='A'$braces_stack
  2035.  
  2036. # Counting complex brackets (for brackets-highlighter): 1. [[ as command
  2037. _FAST_COMPLEX_BRACKETS+=( $(( _start_pos-__PBUFLEN )) $(( _start_pos-__PBUFLEN + 1 )) )
  2038. elif [[ $__arg == "for" ]]; then
  2039. (( next_word = next_word | 32 )) # BIT_for
  2040. elif [[ $__arg == "case" ]]; then
  2041. (( next_word = BIT_case_preamble ))
  2042. elif [[ $__arg = (typeset|declare|local|float|integer|export|readonly) ]]; then
  2043. braces_stack='T'$braces_stack
  2044. fi
  2045. ;;
  2046. 'suffix alias') __style=${FAST_THEME_NAME}suffix-alias;;
  2047. 'global alias') __style=${FAST_THEME_NAME}global-alias;;
  2048. alias)
  2049. if [[ $__arg = ?*'='* ]]; then
  2050. # The so called (by old code) "insane_alias"
  2051. __style=${FAST_THEME_NAME}unknown-token
  2052. else
  2053. __style=${FAST_THEME_NAME}alias
  2054. (( ${+aliases} )) && alias_target=${aliases[$__arg]} || alias_target="${"$(alias -- $__arg)"#*=}"
  2055. [[ ${__FAST_HIGHLIGHT_TOKEN_TYPES[$alias_target]} = "1" && $__arg_type != "1" ]] && __FAST_HIGHLIGHT_TOKEN_TYPES[$__arg]="1"
  2056. fi
  2057. ;;
  2058. builtin) [[ $__arg = "[" ]] && {
  2059. __style=${FAST_THEME_NAME}single-sq-bracket
  2060. _FAST_COMPLEX_BRACKETS+=( $(( _start_pos-__PBUFLEN )) )
  2061. } || __style=${FAST_THEME_NAME}builtin
  2062. # T - typeset, etc. mode
  2063. [[ $__arg = (typeset|declare|local|float|integer|export|readonly) ]] && braces_stack='T'$braces_stack
  2064. [[ $__arg = eval ]] && (( next_word = next_word | 256 ))
  2065. ;;
  2066. function) __style=${FAST_THEME_NAME}function;;
  2067. command) __style=${FAST_THEME_NAME}command;;
  2068. hashed) __style=${FAST_THEME_NAME}hashed-command;;
  2069. dirpath) __style=${FAST_THEME_NAME}path-to-dir;;
  2070. none) # Assign?
  2071. if [[ $__arg == [a-zA-Z_][a-zA-Z0-9_]#(|\[[^\]]#\])(|[^\]]#\])(|[+])=* || $__arg == [0-9]##(|[+])=* || ( $braces_stack = T* && ${__arg_type} != 3 ) ]]; then
  2072. __style=${FAST_THEME_NAME}assign
  2073. [[ $__arg = ?*[=]* ]] && FAST_ASSIGNS_SEEN[${__arg%%=*}]=1
  2074.  
  2075. # Handle array assignment
  2076. [[ $__arg = (#b)*=(\()*(\))* || $__arg = (#b)*=(\()* ]] && {
  2077. (( __start=_start_pos-__PBUFLEN+${mbegin[1]}-1, __end=__start+1, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}assign-array-bracket]}")
  2078. # Counting complex brackets (for brackets-highlighter): 2. ( in array assign
  2079. _FAST_COMPLEX_BRACKETS+=( $__start )
  2080. (( mbegin[2] >= 1 )) && {
  2081. (( __start=_start_pos-__PBUFLEN+${mbegin[2]}-1, __end=__start+1, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}assign-array-bracket]}")
  2082. # Counting complex brackets (for brackets-highlighter): 3a. ) in array assign
  2083. _FAST_COMPLEX_BRACKETS+=( $__start )
  2084. } || in_array_assignment=1
  2085. } || { [[ ${braces_stack[1]} != 'T' ]] && (( next_word = (next_word | 1) & ~2 )); }
  2086.  
  2087. # Handle no-string highlight, string "/' highlight, math mode highlight
  2088. local ctmp="\"" dtmp="'"
  2089. itmp=${__arg[(i)$ctmp]}-1 iitmp=${__arg[(i)$dtmp]}-1
  2090. integer jtmp=${__arg[(b:itmp+2:i)$ctmp]} jjtmp=${__arg[(b:iitmp+2:i)$dtmp]}
  2091. (( itmp < iitmp && itmp <= __asize - 1 )) && (( jtmp > __asize && (jtmp = __asize), 1 > 0 )) && \
  2092. (( __start=_start_pos-__PBUFLEN+itmp, __end=_start_pos-__PBUFLEN+jtmp, __start >= 0 )) && \
  2093. reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}double-quoted-argument]}") && \
  2094. { itmp=${__arg[(i)=]}; __arg=${__arg[itmp,__asize]}; (( _start_pos += itmp - 1 ));
  2095. -fast-highlight-string; (( _start_pos = _start_pos - itmp + 1, 1 > 0 )); } || \
  2096. {
  2097. (( iitmp <= __asize - 1 )) && (( jjtmp > __asize && (jjtmp = __asize), 1 > 0 )) && \
  2098. (( __start=_start_pos-__PBUFLEN+iitmp, __end=_start_pos-__PBUFLEN+jjtmp, __start >= 0 )) && \
  2099. reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}single-quoted-argument]}")
  2100. } || \
  2101. {
  2102. itmp=${__arg[(i)=]}; __arg=${__arg[itmp,__asize]}; (( _start_pos += itmp - 1 ));
  2103. [[ ${__arg[2,4]} = '$((' ]] && { -fast-highlight-math-string;
  2104. (( __start=_start_pos-__PBUFLEN+2, __end=__start+2, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}double-paren]}")
  2105. # Counting complex brackets (for brackets-highlighter): 4. $(( in assign argument
  2106. _FAST_COMPLEX_BRACKETS+=( $__start $(( __start + 1 )) )
  2107. (( jtmp = ${__arg[(I)\)\)]}-1, jtmp > 0 )) && {
  2108. (( __start=_start_pos-__PBUFLEN+jtmp, __end=__start+2, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}double-paren]}")
  2109. # Counting complex brackets (for brackets-highlighter): 5. )) in assign argument
  2110. _FAST_COMPLEX_BRACKETS+=( $__start $(( __start + 1 )) )
  2111. }
  2112. } || -fast-highlight-string;
  2113. (( _start_pos = _start_pos - itmp + 1, 1 > 0 ))
  2114. }
  2115. elif [[ $__arg = ${histchars[1]}* && -n ${__arg[2]} ]]; then
  2116. __style=${FAST_THEME_NAME}history-expansion
  2117. elif [[ $__arg == ${histchars[2]}* ]]; then
  2118. __style=${FAST_THEME_NAME}history-expansion
  2119. elif (( __arg_type == 3 )); then
  2120. # This highlights empty commands (semicolon follows nothing) as an error.
  2121. # Zsh accepts them, though.
  2122. (( this_word & 2 )) && __style=${FAST_THEME_NAME}commandseparator
  2123. elif [[ $__arg[1,2] == '((' ]]; then
  2124. # Arithmetic evaluation.
  2125. #
  2126. # Note: prior to zsh-5.1.1-52-g4bed2cf (workers/36669), the ${(z)...}
  2127. # splitter would only output the '((' token if the matching '))' had
  2128. # been typed. Therefore, under those versions of zsh, BUFFER="(( 42"
  2129. # would be highlighted as an error until the matching "))" are typed.
  2130. #
  2131. # We highlight just the opening parentheses, as a reserved word; this
  2132. # is how [[ ... ]] is highlighted, too.
  2133.  
  2134. # ADD
  2135. (( __start=_start_pos-__PBUFLEN, __end=__start+2, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}double-paren]}")
  2136. already_added=1
  2137.  
  2138. # Counting complex brackets (for brackets-highlighter): 6. (( as command
  2139. _FAST_COMPLEX_BRACKETS+=( $__start $(( __start + 1 )) )
  2140.  
  2141. -fast-highlight-math-string
  2142.  
  2143. # ADD
  2144. [[ $__arg[-2,-1] == '))' ]] && {
  2145. (( __start=_end_pos-__PBUFLEN-2, __end=__start+2, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}double-paren]}")
  2146. (( __delimited = __delimited ? 2 : __delimited ))
  2147.  
  2148. # Counting complex brackets (for brackets-highlighter): 7. )) for as-command ((
  2149. _FAST_COMPLEX_BRACKETS+=( $__start $(( __start + 1 )) )
  2150. }
  2151. elif [[ $__arg == '()' ]]; then
  2152. _FAST_COMPLEX_BRACKETS+=( $(( _start_pos-__PBUFLEN )) $(( _start_pos-__PBUFLEN + 1 )) )
  2153. # anonymous function
  2154. __style=${FAST_THEME_NAME}reserved-word
  2155. elif [[ $__arg == $'\x28' ]]; then
  2156. # subshell '(', stack: letter 'R'
  2157. __style=${FAST_THEME_NAME}reserved-word
  2158. braces_stack='R'$braces_stack
  2159. elif [[ $__arg == $'\x29' ]]; then
  2160. # ')', stack: letter 'R' for subshell
  2161. [[ $braces_stack = R* ]] && { braces_stack=${braces_stack#R}; __style=${FAST_THEME_NAME}reserved-word; }
  2162. elif (( this_word & 14 )); then
  2163. __style=${FAST_THEME_NAME}default
  2164. elif [[ $__arg = (';;'|';&'|';|') ]] && (( this_word & BIT_case_code )); then
  2165. (( next_word = (next_word | BIT_case_item) & ~(BIT_case_code+3) ))
  2166. __style=${FAST_THEME_NAME}default
  2167. elif [[ $__arg = \$\([^\(]* ]]; then
  2168. already_added=1
  2169. fi
  2170. ;;
  2171. *)
  2172. # ADD
  2173. # (( __start=_start_pos-__PBUFLEN, __end=_end_pos-__PBUFLEN, __start >= 0 )) && reply+=("$__start $__end commandtypefromthefuture-$REPLY")
  2174. already_added=1
  2175. ;;
  2176. esac
  2177. fi
  2178. # in_redirection || BIT_regular || BIT_sudo_opt || BIT_sudo_arg
  2179. elif (( in_redirection + this_word & 14 ))
  2180. then # $__arg is a non-command word
  2181. case $__arg in
  2182. ']]')
  2183. # A - [[
  2184. [[ $braces_stack = A* ]] && {
  2185. __style=${FAST_THEME_NAME}double-sq-bracket
  2186. (( __delimited = __delimited ? 2 : __delimited ))
  2187. # Counting complex brackets (for brackets-highlighter): 8a. ]] for as-command [[
  2188. _FAST_COMPLEX_BRACKETS+=( $(( _start_pos-__PBUFLEN )) $(( _start_pos-__PBUFLEN+1 )) )
  2189. } || {
  2190. [[ $braces_stack = *A* ]] && {
  2191. __style=${FAST_THEME_NAME}unknown-token
  2192. # Counting complex brackets (for brackets-highlighter): 8b. ]] for as-command [[
  2193. _FAST_COMPLEX_BRACKETS+=( $(( _start_pos-__PBUFLEN )) $(( _start_pos-__PBUFLEN+1 )) )
  2194. } || __style=${FAST_THEME_NAME}default
  2195. }
  2196. braces_stack=${braces_stack#A}
  2197. ;;
  2198. ']')
  2199. __style=${FAST_THEME_NAME}single-sq-bracket
  2200. _FAST_COMPLEX_BRACKETS+=( $(( _start_pos-__PBUFLEN )) )
  2201. ;;
  2202. $'\x28')
  2203. # '(' inside [[
  2204. __style=${FAST_THEME_NAME}reserved-word
  2205. braces_stack='R'$braces_stack
  2206. ;;
  2207. $'\x29') # ')' - subshell or end of array assignment
  2208. if (( in_array_assignment )); then
  2209. in_array_assignment=0
  2210. (( next_word = next_word | 1 ))
  2211. (( __start=_start_pos-__PBUFLEN, __end=_end_pos-__PBUFLEN, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}assign-array-bracket]}")
  2212. already_added=1
  2213. # Counting complex brackets (for brackets-highlighter): 3b. ) in array assign
  2214. _FAST_COMPLEX_BRACKETS+=( $__start )
  2215. elif [[ $braces_stack = R* ]]; then
  2216. braces_stack=${braces_stack#R}
  2217. __style=${FAST_THEME_NAME}reserved-word
  2218. # Zsh doesn't tokenize final ) if it's just single ')',
  2219. # but logically what's below is correct, so it is kept
  2220. # in case Zsh will be changed / fixed, etc.
  2221. elif [[ $braces_stack = F* ]]; then
  2222. __style=${FAST_THEME_NAME}builtin
  2223. fi
  2224. ;;
  2225. $'\x28\x29') # '()' - possibly a function definition
  2226. # || false # TODO: or if the previous word was a command word
  2227. (( FAST_HIGHLIGHT[multi_func_def] )) && (( next_word = next_word | 1 ))
  2228. __style=${FAST_THEME_NAME}reserved-word
  2229. _FAST_COMPLEX_BRACKETS+=( $(( _start_pos-__PBUFLEN )) $(( _start_pos-__PBUFLEN + 1 )) )
  2230. # Remove possible annoying unknown-token __style, or misleading function __style
  2231. reply[-1]=()
  2232. __fast_highlight_main__command_type_cache[$active_command]="function"
  2233. ;;
  2234. '--'*) [[ $__arg == "--" ]] && { _was_double_hyphen=1; __style=${FAST_THEME_NAME}double-hyphen-option; } || {
  2235. (( !_was_double_hyphen )) && {
  2236. [[ "$__arg" = (#b)(--[a-zA-Z0-9_]##)=(*) ]] && {
  2237. (( __start=_start_pos-__PBUFLEN, __end=_end_pos-__PBUFLEN, __start >= 0 )) && \
  2238. reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}double-hyphen-option]}")
  2239. (( __start=_start_pos-__PBUFLEN+1+mend[1], __end=_end_pos-__PBUFLEN, __start >= 0 )) && \
  2240. reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}optarg-${${${(M)match[2]:#<->}:+number}:-string}]}")
  2241. already_added=1
  2242. } || __style=${FAST_THEME_NAME}double-hyphen-option
  2243. } || __style=${FAST_THEME_NAME}default
  2244. }
  2245. ;;
  2246. '-'*) (( !_was_double_hyphen )) && __style=${FAST_THEME_NAME}single-hyphen-option || __style=${FAST_THEME_NAME}default;;
  2247. \$\'*)
  2248. (( __start=_start_pos-__PBUFLEN, __end=_end_pos-__PBUFLEN, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}dollar-quoted-argument]}")
  2249. -fast-highlight-dollar-string
  2250. already_added=1
  2251. ;;
  2252. [\"\']*|[^\"\\]##([\\][\\])#\"*|[^\'\\]##([\\][\\])#\'*)
  2253. if (( this_word & 256 )) && [[ $__arg = [\'\"]* ]]; then
  2254. if [[ -n ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}secondary]} ]]; then
  2255. __idx=1
  2256. _mybuf=$FAST_THEME_NAME
  2257. FAST_THEME_NAME=${${${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}secondary]}:t:r}#(XDG|LOCAL|HOME|OPT):}
  2258. (( ${+FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}default]} )) || source $FAST_WORK_DIR/secondary_theme.zsh
  2259. else
  2260. __idx=0
  2261. fi
  2262. -fast-highlight-process "$PREBUFFER" ${${__arg%[\'\"]}#[\'\"]} $(( _start_pos + 1 ))
  2263. (( __idx )) && FAST_THEME_NAME=$_mybuf
  2264. already_added=1
  2265. else
  2266. [[ $__arg = *([^\\][\#][\#]|"(#b)"|"(#B)"|"(#m)"|"(#c")* && $highlight_glob -ne 0 ]] && \
  2267. (( __start=_start_pos-__PBUFLEN, __end=_end_pos-__PBUFLEN, __start >= 0 )) && \
  2268. reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}globbing-ext]}")
  2269. # Reusing existing vars, treat this code like C++ STL
  2270. # header, full of underscores and unhelpful var names
  2271. itmp=0 __workbuf=$__arg __tmp="" cdpath_dir=$__arg
  2272. while [[ $__workbuf = (#b)[^\"\'\\]#(([\"\'])|[\\](*))(*) ]]; do
  2273. [[ -n ${match[3]} ]] && {
  2274. itmp+=${mbegin[1]}
  2275. # Optionally skip 1 quoted char
  2276. [[ $__tmp = \' ]] && __workbuf=${match[3]} || { itmp+=1; __workbuf=${match[3]:1}; }
  2277. } || {
  2278. itmp+=${mbegin[1]}
  2279. __workbuf=${match[4]}
  2280. # Toggle quoting
  2281. [[ ( ${match[1]} = \" && $__tmp != \' ) || ( ${match[1]} = \' && $__tmp != \" ) ]] && {
  2282. [[ $__tmp = [\"\'] ]] && {
  2283. # End of quoting
  2284. (( __start=_start_pos-__PBUFLEN+iitmp-1, __end=_start_pos-__PBUFLEN+itmp, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}${${${__tmp#\'}:+double-quoted-argument}:-single-quoted-argument}]}")
  2285. already_added=1
  2286.  
  2287. [[ $__tmp = \" ]] && {
  2288. __arg=${cdpath_dir[iitmp+1,itmp-1]}
  2289. (( _start_pos += iitmp - 1 + 1 ))
  2290. -fast-highlight-string
  2291. (( _start_pos = _start_pos - iitmp + 1 - 1 ))
  2292. }
  2293. # The end-of-quoting proper algorithm action
  2294. __tmp=
  2295. } || {
  2296. # Beginning of quoting
  2297. iitmp=itmp
  2298. # The beginning-of-quoting proper algorithm action
  2299. __tmp=${match[1]}
  2300. }
  2301. }
  2302. }
  2303. done
  2304. [[ $__tmp = [\"\'] ]] && {
  2305. (( __start=_start_pos-__PBUFLEN+iitmp-1, __end=_start_pos-__PBUFLEN+__asize, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}${${${__tmp#\'}:+double-quoted-argument}:-single-quoted-argument}]}")
  2306. already_added=1
  2307.  
  2308. [[ $__tmp = \" ]] && {
  2309. __arg=${cdpath_dir[iitmp+1,__asize]}
  2310. (( _start_pos += iitmp - 1 + 1 ))
  2311. -fast-highlight-string
  2312. (( _start_pos = _start_pos - iitmp + 1 - 1 ))
  2313. }
  2314. }
  2315. fi
  2316. ;;
  2317. \$\(\(*)
  2318. already_added=1
  2319. -fast-highlight-math-string
  2320. # ADD
  2321. (( __start=_start_pos-__PBUFLEN+1, __end=__start+2, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}double-paren]}")
  2322. # Counting complex brackets (for brackets-highlighter): 9. $(( as argument
  2323. _FAST_COMPLEX_BRACKETS+=( $__start $(( __start + 1 )) )
  2324. # ADD
  2325. [[ $__arg[-2,-1] == '))' ]] && (( __start=_end_pos-__PBUFLEN-2, __end=__start+2, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}double-paren]}")
  2326. # Counting complex brackets (for brackets-highlighter): 10. )) for as-argument $((
  2327. _FAST_COMPLEX_BRACKETS+=( $__start $(( __start + 1 )) )
  2328. ;;
  2329. '`'*) __style=${FAST_THEME_NAME}back-quoted-argument;;
  2330. '((') # 'F' - (( after for
  2331. (( this_word & 32 )) && {
  2332. braces_stack='F'$braces_stack
  2333. __style=${FAST_THEME_NAME}double-paren
  2334. # Counting complex brackets (for brackets-highlighter): 11. (( as for-syntax
  2335. _FAST_COMPLEX_BRACKETS+=( $(( _start_pos-__PBUFLEN )) $(( _start_pos-__PBUFLEN+1 )) )
  2336. # This is set after __arg_type == 2, and also here,
  2337. # when another alternate-syntax capable command occurs
  2338. __delimited=1
  2339. }
  2340. ;;
  2341. '))') # 'F' - (( after for
  2342. [[ $braces_stack = F* ]] && {
  2343. braces_stack=${braces_stack#F}
  2344. __style=${FAST_THEME_NAME}double-paren
  2345. # Counting complex brackets (for brackets-highlighter): 12. )) as for-syntax
  2346. _FAST_COMPLEX_BRACKETS+=( $(( _start_pos-__PBUFLEN )) $(( _start_pos-__PBUFLEN+1 )) )
  2347. (( __delimited = __delimited ? 2 : __delimited ))
  2348. }
  2349. ;;
  2350. '<<<')
  2351. (( next_word = (next_word | 128) & ~3 ))
  2352. [[ ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}here-string-tri]} != "none" ]] && (( __start=_start_pos-__PBUFLEN, __end=_end_pos-__PBUFLEN, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}here-string-tri]}")
  2353. already_added=1
  2354. ;;
  2355. *) # F - (( after for
  2356. if [[ $braces_stack = F* ]]; then
  2357. -fast-highlight-string
  2358. _mybuf=$__arg
  2359. __idx=_start_pos
  2360. while [[ $_mybuf = (#b)[^a-zA-Z\{\$]#([a-zA-Z][a-zA-Z0-9]#)(*) ]]; do
  2361. (( __start=__idx-__PBUFLEN+${mbegin[1]}-1, __end=__idx-__PBUFLEN+${mend[1]}+1-1, __start >= 0 )) && \
  2362. reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}for-loop-variable]}")
  2363. __idx+=${mend[1]}
  2364. _mybuf=${match[2]}
  2365. done
  2366.  
  2367. _mybuf=$__arg
  2368. __idx=_start_pos
  2369. while [[ $_mybuf = (#b)[^+\<\>=:\*\|\&\^\~-]#([+\<\>=:\*\|\&\^\~-]##)(*) ]]; do
  2370. (( __start=__idx-__PBUFLEN+${mbegin[1]}-1, __end=__idx-__PBUFLEN+${mend[1]}+1-1, __start >= 0 )) && \
  2371. reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}for-loop-operator]}")
  2372. __idx+=${mend[1]}
  2373. _mybuf=${match[2]}
  2374. done
  2375.  
  2376. _mybuf=$__arg
  2377. __idx=_start_pos
  2378. while [[ $_mybuf = (#b)[^0-9]#([0-9]##)(*) ]]; do
  2379. (( __start=__idx-__PBUFLEN+${mbegin[1]}-1, __end=__idx-__PBUFLEN+${mend[1]}+1-1, __start >= 0 )) && \
  2380. reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}for-loop-number]}")
  2381. __idx+=${mend[1]}
  2382. _mybuf=${match[2]}
  2383. done
  2384.  
  2385. if [[ $__arg = (#b)[^\;]#(\;)[\ ]# ]]; then
  2386. (( __start=_start_pos-__PBUFLEN+${mbegin[1]}-1, __end=_start_pos-__PBUFLEN+${mend[1]}+1-1, __start >= 0 )) && \
  2387. reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}for-loop-separator]}")
  2388. fi
  2389.  
  2390. already_added=1
  2391. elif [[ $__arg = *([^\\][\#][\#]|"(#b)"|"(#B)"|"(#m)"|"(#c")* ]]; then
  2392. (( highlight_glob )) && __style=${FAST_THEME_NAME}globbing-ext || __style=${FAST_THEME_NAME}default
  2393. elif [[ $__arg = ([*?]*|*[^\\][*?]*) ]]; then
  2394. (( highlight_glob )) && __style=${FAST_THEME_NAME}globbing || __style=${FAST_THEME_NAME}default
  2395. elif [[ $__arg = \$* ]]; then
  2396. __style=${FAST_THEME_NAME}variable
  2397. elif [[ $__arg = $'\x7d' && $braces_stack = Y* && ${FAST_HIGHLIGHT[right_brace_is_recognised_everywhere]} = "1" ]]; then
  2398. # right brace, i.e. $'\x7d' == '}'
  2399. # Parsing rule: # {
  2400. #
  2401. # Additionally, `tt(})' is recognized in any position if neither the
  2402. # tt(IGNORE_BRACES) option nor the tt(IGNORE_CLOSE_BRACES) option is set."""
  2403. braces_stack=${braces_stack#Y}
  2404. __style=${FAST_THEME_NAME}reserved-word
  2405. (( next_word = next_word | 16 ))
  2406. elif [[ $__arg = (';;'|';&'|';|') ]] && (( this_word & BIT_case_code )); then
  2407. (( next_word = (next_word | BIT_case_item) & ~(BIT_case_code+3) ))
  2408. __style=${FAST_THEME_NAME}default
  2409. elif [[ $__arg = ${histchars[1]}* && -n ${__arg[2]} ]]; then
  2410. __style=${FAST_THEME_NAME}history-expansion
  2411. elif (( __arg_type == 3 )); then
  2412. __style=${FAST_THEME_NAME}commandseparator
  2413. elif (( in_redirection == 2 )); then
  2414. __style=${FAST_THEME_NAME}redirection
  2415. elif (( ${+galiases[(e)$__arg]} )); then
  2416. __style=${FAST_THEME_NAME}global-alias
  2417. else
  2418. if [[ ${FAST_HIGHLIGHT[no_check_paths]} != 1 ]]; then
  2419. if [[ ${FAST_HIGHLIGHT[use_async]} != 1 ]]; then
  2420. if -fast-highlight-check-path noasync; then
  2421. # ADD
  2422. (( __start=_start_pos-__PBUFLEN, __end=_end_pos-__PBUFLEN, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}")
  2423. already_added=1
  2424.  
  2425. # TODO: path separators, optimize and add to async code-path
  2426. [[ -n ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}path_pathseparator]} && ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}path]} != ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}path_pathseparator]} ]] && {
  2427. for (( __pos = _start_pos; __pos <= _end_pos; __pos++ )) ; do
  2428. # ADD
  2429. [[ ${__buf[__pos]} == "/" ]] && (( __start=__pos-__PBUFLEN, __start >= 0 )) && reply+=("$(( __start - 1 )) $__start ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}path_pathseparator]}")
  2430. done
  2431. }
  2432. else
  2433. __style=${FAST_THEME_NAME}default
  2434. fi
  2435. else
  2436. if [[ -z ${FAST_HIGHLIGHT[cache-path-${(q)__arg}-${_start_pos}]} || $(( EPOCHSECONDS - FAST_HIGHLIGHT[cache-path-${(q)__arg}-${_start_pos}-born-at] )) -gt 8 ]]; then
  2437. if [[ $LASTWIDGET != *-or-beginning-search ]]; then
  2438. exec {PCFD}< <(-fast-highlight-check-path; sleep 5)
  2439. command sleep 0
  2440. FAST_HIGHLIGHT[path-queue]+=";$_start_pos $_end_pos;"
  2441. is-at-least 5.0.6 && __pos=1 || __pos=0
  2442. zle -F ${${__pos:#0}:+-w} $PCFD fast-highlight-check-path-handler
  2443. already_added=1
  2444. else
  2445. __style=${FAST_THEME_NAME}default
  2446. fi
  2447. elif [[ ${FAST_HIGHLIGHT[cache-path-${(q)__arg}-${_start_pos}]%D} -eq 1 ]]; then
  2448. (( __start=_start_pos-__PBUFLEN, __end=_end_pos-__PBUFLEN, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}path${${(M)FAST_HIGHLIGHT[cache-path-${(q)__arg}-${_start_pos}]%D}:+-to-dir}]}")
  2449. already_added=1
  2450. else
  2451. __style=${FAST_THEME_NAME}default
  2452. fi
  2453. fi
  2454. else
  2455. __style=${FAST_THEME_NAME}default
  2456. fi
  2457. fi
  2458. ;;
  2459. esac
  2460. elif (( this_word & 128 ))
  2461. then
  2462. (( next_word = (next_word | 2) & ~129 ))
  2463. [[ ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}here-string-text]} != "none" ]] && (( __start=_start_pos-__PBUFLEN, __end=_end_pos-__PBUFLEN, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}here-string-text]}")
  2464. -fast-highlight-string ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}here-string-var]:#none}
  2465. already_added=1
  2466. elif (( this_word & (BIT_case_preamble + BIT_case_item) ))
  2467. then
  2468. if (( this_word & BIT_case_preamble )); then
  2469. [[ $__arg = "in" ]] && {
  2470. __style=${FAST_THEME_NAME}reserved-word
  2471. (( next_word = BIT_case_item ))
  2472. } || {
  2473. __style=${FAST_THEME_NAME}case-input
  2474. (( next_word = BIT_case_preamble ))
  2475. }
  2476. else
  2477. if (( this_word & BIT_case_nempty_item == 0 )) && [[ $__arg = "esac" ]]; then
  2478. (( next_word = 1 ))
  2479. __style=${FAST_THEME_NAME}reserved-word
  2480. elif [[ $__arg = [\)\(] ]]; then
  2481. __style=${FAST_THEME_NAME}case-parentheses
  2482. [[ $__arg = \) ]] && (( next_word = BIT_case_code | 1 )) || (( next_word = BIT_case_item | BIT_case_nempty_item ))
  2483. _FAST_COMPLEX_BRACKETS+=( $(( _start_pos-__PBUFLEN )) )
  2484. else
  2485. (( next_word = BIT_case_item | BIT_case_nempty_item ))
  2486. __style=${FAST_THEME_NAME}case-condition
  2487. fi
  2488. fi
  2489. fi
  2490.  
  2491. # ADD
  2492. (( already_added == 0 )) && [[ ${FAST_HIGHLIGHT_STYLES[$__style]} != "none" ]] && (( __start=_start_pos-__PBUFLEN, __end=_end_pos-__PBUFLEN, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}")
  2493.  
  2494. if (( (__arg_type == 3) && ((this_word & (BIT_case_preamble|BIT_case_item)) == 0) )); then
  2495. if [[ $__arg == ';' ]] && (( in_array_assignment )); then
  2496. # literal newline inside an array assignment
  2497. (( next_word = 2 | (next_word & BIT_case_code) ))
  2498. elif [[ -n ${braces_stack[(r)A]} ]]; then
  2499. # 'A' in stack -> inside [[ ... ]]
  2500. (( next_word = 2 | (next_word & BIT_case_code) ))
  2501. else
  2502. braces_stack=${braces_stack#T}
  2503. (( next_word = 1 | (next_word & BIT_case_code) ))
  2504. highlight_glob=1
  2505. # A new command means that we should not expect that alternate
  2506. # syntax will occur (this is also in the ';' short-path), but
  2507. # || and && mean going down just 1 step, not all the way to 0
  2508. [[ $__arg != ("||"|"&&") ]] && __delimited=0 || (( __delimited = __delimited == 2 ? 1 : __delimited ))
  2509. fi
  2510. elif (( ( (__arg_type == 1) || (__arg_type == 2) ) && (this_word & 1) )); then # (( __arg_type == 1 || __arg_type == 2 )) && (( this_word & 1 ))
  2511. __delimited=1
  2512. (( next_word = 1 | (next_word & (64 | BIT_case_code)) ))
  2513. elif [[ $__arg == "repeat" ]] && (( this_word & 1 )); then
  2514. __delimited=1
  2515. # skip the repeat-count word
  2516. in_redirection=2
  2517. # The redirection mechanism assumes $this_word describes the word
  2518. # following the redirection. Make it so.
  2519. #
  2520. # That word can be a command word with shortloops (`repeat 2 ls`)
  2521. # or a command separator (`repeat 2; ls` or `repeat 2; do ls; done`).
  2522. #
  2523. # The repeat-count word will be handled like a redirection target.
  2524. (( this_word = 3 ))
  2525. fi
  2526. _start_pos=$_end_pos
  2527. # This is the default/common codepath.
  2528. (( this_word = in_redirection == 0 ? next_word : this_word )) #else # Stall $this_word.
  2529. done
  2530.  
  2531. # Do we have whole buffer? I.e. start at zero
  2532. [[ $3 != 0 ]] && return 0
  2533.  
  2534. # The loop overwrites ")" with "x", except those from $( ) substitution
  2535. #
  2536. # __pos: current nest level, starts from 0
  2537. # __workbuf: copy of __buf, with limit on 250 characters
  2538. # __idx: index in whole command line buffer
  2539. # __list: list of coordinates of ) which shouldn't be ovewritten
  2540. _mybuf=${__buf[1,250]} __workbuf=$_mybuf __idx=0 __pos=0 __list=()
  2541.  
  2542. while [[ $__workbuf = (#b)[^\(\)]#([\(\)])(*) ]]; do
  2543. if [[ ${match[1]} == \( ]]; then
  2544. __arg=${_mybuf[__idx+${mbegin[1]}-1,__idx+${mbegin[1]}-1+2]}
  2545. [[ $__arg = '$('[^\(] ]] && __list+=( $__pos )
  2546. [[ $__arg = '$((' ]] && _mybuf[__idx+${mbegin[1]}-1]=x
  2547. # Increase parenthesis level
  2548. __pos+=1
  2549. else
  2550. # Decrease parenthesis level
  2551. __pos=__pos-1
  2552. [[ -z ${__list[(r)$__pos]} ]] && [[ $__pos -gt 0 ]] && _mybuf[__idx+${mbegin[1]}]=x
  2553. fi
  2554. __idx+=${mbegin[2]}-1
  2555. __workbuf=${match[2]}
  2556. done
  2557.  
  2558. # Run on fake buffer with replaced parentheses: ")" into "x"
  2559. __inputs=( ${(0)${(S)_mybuf//(#b)*\$\(([^\)]#)(\)|(#e))/${mbegin[1]};${mend[1]}${__nul}}%$__nul*} )
  2560. if [[ ${__inputs[1]} != $_mybuf ]]; then
  2561. if [[ -n ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}secondary]} ]]; then
  2562. __idx=1
  2563. __tmp=$FAST_THEME_NAME
  2564. FAST_THEME_NAME=${${${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}secondary]}:t:r}#(XDG|LOCAL|HOME|OPT):}
  2565. (( ${+FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}default]} )) || source $FAST_WORK_DIR/secondary_theme.zsh
  2566. else
  2567. __idx=0
  2568. fi
  2569. for _mybuf in $__inputs; do
  2570. # Pass authentic buffer for recursive analysis
  2571. -fast-highlight-process "$PREBUFFER" ${__buf[${_mybuf%%;*},${_mybuf##*;}]} $(( ${_mybuf%%;*} - 1 ))
  2572. done
  2573. # Restore theme
  2574. (( __idx )) && FAST_THEME_NAME=$__tmp
  2575. fi
  2576.  
  2577. return 0
  2578. }
  2579.  
  2580. -fast-highlight-check-path()
  2581. {
  2582. [[ $1 != "noasync" ]] && {
  2583. print -r -- ${sysparams[pid]}
  2584. # This is to fill cache
  2585. print -r -- $__arg
  2586. }
  2587.  
  2588. : ${expanded_path:=${(Q)~__arg}}
  2589. [[ -n ${FAST_BLIST_PATTERNS[(k)${${(M)expanded_path:#/*}:-$PWD/$expanded_path}]} ]] && { [[ $1 != "noasync" ]] && print -r -- "- $_start_pos $_end_pos"; return 1; }
  2590.  
  2591. [[ -z $expanded_path ]] && { [[ $1 != "noasync" ]] && print -r -- "- $_start_pos $_end_pos"; return 1; }
  2592. [[ -d $expanded_path ]] && { [[ $1 != "noasync" ]] && print -r -- "$_start_pos ${_end_pos}D" || __style=${FAST_THEME_NAME}path-to-dir; return 0; }
  2593. [[ -e $expanded_path ]] && { [[ $1 != "noasync" ]] && print -r -- "$_start_pos $_end_pos" || __style=${FAST_THEME_NAME}path; return 0; }
  2594.  
  2595. # Search the path in CDPATH, only for CD command
  2596. [[ $active_command = "cd" ]] && for cdpath_dir in $cdpath; do
  2597. [[ -d $cdpath_dir/$expanded_path ]] && { [[ $1 != "noasync" ]] && print -r -- "$_start_pos ${_end_pos}D" || __style=${FAST_THEME_NAME}path-to-dir; return 0; }
  2598. [[ -e $cdpath_dir/$expanded_path ]] && { [[ $1 != "noasync" ]] && print -r -- "$_start_pos $_end_pos" || __style=${FAST_THEME_NAME}path; return 0; }
  2599. done
  2600.  
  2601. # It's not a path.
  2602. [[ $1 != "noasync" ]] && print -r -- "- $_start_pos $_end_pos"
  2603. return 1
  2604. }
  2605.  
  2606. -fast-highlight-check-path-handler() {
  2607. local IFS=$'\n' pid PCFD=$1 line stripped val
  2608. integer idx
  2609.  
  2610. if read -r -u $PCFD pid; then
  2611. if read -r -u $PCFD val; then
  2612. if read -r -u $PCFD line; then
  2613. stripped=${${line#- }%D}
  2614. FAST_HIGHLIGHT[cache-path-${(q)val}-${stripped%% *}-born-at]=$EPOCHSECONDS
  2615. idx=${${FAST_HIGHLIGHT[path-queue]}[(I)$stripped]}
  2616. (( idx > 0 )) && {
  2617. if [[ $line != -* ]]; then
  2618. FAST_HIGHLIGHT[cache-path-${(q)val}-${stripped%% *}]="1${(M)line%D}"
  2619. region_highlight+=("${line%% *} ${${line##* }%D} ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}path${${(M)line%D}:+-to-dir}]}")
  2620. else
  2621. FAST_HIGHLIGHT[cache-path-${(q)val}-${stripped%% *}]=0
  2622. fi
  2623. val=${FAST_HIGHLIGHT[path-queue]}
  2624. val[idx-1,idx+${#stripped}]=""
  2625. FAST_HIGHLIGHT[path-queue]=$val
  2626. [[ ${FAST_HIGHLIGHT[cache-path-${(q)val}-${stripped%% *}]%D} = 1 && ${#val} -le 27 ]] && zle .redisplay
  2627. }
  2628. fi
  2629. fi
  2630. kill -9 $pid 2>/dev/null
  2631. fi
  2632.  
  2633. zle -F -w ${PCFD}
  2634. exec {PCFD}<&-
  2635. }
  2636.  
  2637. zle -N -- fast-highlight-check-path-handler -fast-highlight-check-path-handler
  2638.  
  2639. # Highlight special blocks inside double-quoted strings
  2640. #
  2641. # The while [[ ... ]] pattern is logically ((A)|(B)|(C)|(D)|(E))(*), where:
  2642. # - A matches $var[abc]
  2643. # - B matches ${(...)var[abc]}
  2644. # - C matches $
  2645. # - D matches \$ or \" or \'
  2646. # - E matches \*
  2647. #
  2648. # and the first condition -n ${match[7] uses D to continue searching when
  2649. # backslash-something (not ['"$]) is occured.
  2650. #
  2651. # $1 - additional style to glue-in to added style
  2652. -fast-highlight-string()
  2653. {
  2654. _mybuf=$__arg
  2655. __idx=_start_pos
  2656.  
  2657. # 7 8
  2658. while [[ $_mybuf = (#b)[^\$\\]#((\$(#B)([#+^=~](#c1,2))(#c0,1)(#B)([a-zA-Z_:][a-zA-Z0-9_:]#|[0-9]##)(#b)(\[[^\]]#\])(#c0,1))|(\$[{](#B)([#+^=~](#c1,2))(#c0,1)(#b)(\([a-zA-Z0-9_:@%#]##\))(#c0,1)[a-zA-Z0-9_:#]##(\[[^\]]#\])(#c0,1)[}])|\$|[\\][\'\"\$]|[\\](*))(*) ]]; do
  2659. [[ -n ${match[7]} ]] && {
  2660. # Skip following char – it is quoted. Choice is
  2661. # made to not highlight such quoting
  2662. __idx+=${mbegin[1]}+1
  2663. _mybuf=${match[7]:1}
  2664. } || {
  2665. __idx+=${mbegin[1]}-1
  2666. _end_idx=__idx+${mend[1]}-${mbegin[1]}+1
  2667. _mybuf=${match[8]}
  2668.  
  2669. # ADD
  2670. (( __start=__idx-__PBUFLEN, __end=_end_idx-__PBUFLEN, __start >= 0 )) && reply+=("$__start $__end ${${1:+$1}:-${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}back-or-dollar-double-quoted-argument]}}")
  2671.  
  2672. __idx=_end_idx
  2673. }
  2674. done
  2675. return 0
  2676. }
  2677.  
  2678. # Highlight math and non-math context variables inside $(( )) and (( ))
  2679. #
  2680. # The while [[ ... ]] pattern is logically ((A)|(B)|(C)|(D))(*), where:
  2681. # - A matches $var[abc]
  2682. # - B matches ${(...)var[abc]}
  2683. # - C matches $
  2684. # - D matches words [a-zA-Z]## (variables)
  2685. #
  2686. # Parameters used: _mybuf, __idx, _end_idx, __style
  2687. -fast-highlight-math-string()
  2688. {
  2689. _mybuf=$__arg
  2690. __idx=_start_pos
  2691.  
  2692. # 7
  2693. while [[ $_mybuf = (#b)[^\$_a-zA-Z0-9]#((\$(#B)(+|)(#B)([a-zA-Z_:][a-zA-Z0-9_:]#|[0-9]##)(#b)(\[[^\]]##\])(#c0,1))|(\$[{](#B)(+|)(#b)(\([a-zA-Z0-9_:@%#]##\))(#c0,1)[a-zA-Z0-9_:#]##(\[[^\]]##\])(#c0,1)[}])|\$|[a-zA-Z_][a-zA-Z0-9_]#|[0-9]##)(*) ]]; do
  2694. __idx+=${mbegin[1]}-1
  2695. _end_idx=__idx+${mend[1]}-${mbegin[1]}+1
  2696. _mybuf=${match[7]}
  2697.  
  2698. [[ ${match[1]} = [0-9]* ]] && __style=${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}mathnum]} || {
  2699. [[ ${match[1]} = [a-zA-Z_]* ]] && {
  2700. [[ -n ${(P)match[1]} || ${FAST_ASSIGNS_SEEN[${match[1]}]} = 1 ]] && __style=${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}mathvar]} || __style=${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}matherr]}
  2701. } || {
  2702. [[ ${match[1]} = "$"* ]] && {
  2703. match[1]=${match[1]//[\{\}\+]/}
  2704. [[ ${match[1]} = "$" || -n ${(P)${match[1]:1}} || ${FAST_ASSIGNS_SEEN[${match[1]:1}]} = 1 ]] && __style=${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}back-or-dollar-double-quoted-argument]} || __style=${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}matherr]}
  2705. }
  2706. }
  2707. }
  2708.  
  2709. # ADD
  2710. [[ $__style != "none" && -n $__style ]] && (( __start=__idx-__PBUFLEN, __end=_end_idx-__PBUFLEN, __start >= 0 )) && reply+=("$__start $__end $__style")
  2711.  
  2712. __idx=_end_idx
  2713. done
  2714. }
  2715.  
  2716. # Highlight special chars inside dollar-quoted strings
  2717. -fast-highlight-dollar-string()
  2718. {
  2719. local i j k __style
  2720. local AA
  2721. integer c
  2722. # Starting dollar-quote is at 1:2, so __start parsing at offset 3 in the string.
  2723. for (( i = 3 ; i < _end_pos - _start_pos ; i += 1 )) ; do
  2724. (( j = i + _start_pos - 1 ))
  2725. (( k = j + 1 ))
  2726. case ${__arg[$i]} in
  2727. "\\") __style=${FAST_THEME_NAME}back-dollar-quoted-argument
  2728. for (( c = i + 1 ; c <= _end_pos - _start_pos ; c += 1 )); do
  2729. [[ ${__arg[$c]} != ([0-9xXuUa-fA-F]) ]] && break
  2730. done
  2731. AA=$__arg[$i+1,$c-1]
  2732. # Matching for HEX and OCT values like \0xA6, \xA6 or \012
  2733. if [[ "$AA" =~ "^(x|X)[0-9a-fA-F]{1,2}"
  2734. || "$AA" =~ "^[0-7]{1,3}"
  2735. || "$AA" =~ "^u[0-9a-fA-F]{1,4}"
  2736. || "$AA" =~ "^U[0-9a-fA-F]{1,8}"
  2737. ]]; then
  2738. (( k += $#MATCH ))
  2739. (( i += $#MATCH ))
  2740. else
  2741. if (( __asize > i+1 )) && [[ $__arg[i+1] == [xXuU] ]]; then
  2742. # \x not followed by hex digits is probably an error
  2743. __style=${FAST_THEME_NAME}unknown-token
  2744. fi
  2745. (( k += 1 )) # Color following char too.
  2746. (( i += 1 )) # Skip parsing the escaped char.
  2747. fi
  2748. ;;
  2749. *) continue ;;
  2750.  
  2751. esac
  2752. # ADD
  2753. (( __start=j-__PBUFLEN, __end=k-__PBUFLEN, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}")
  2754. done
  2755. }
  2756.  
  2757. -fast-highlight-init() {
  2758. _FAST_COMPLEX_BRACKETS=()
  2759. __fast_highlight_main__command_type_cache=()
  2760. }
  2761.  
  2762. typeset -ga FSH_LIST
  2763. -fsh_sy_h_shappend() {
  2764. FSH_LIST+=( "$(( $1 - 1 ));;$(( $2 ))" )
  2765. }
  2766.  
  2767. functions -M fsh_sy_h_append 2 2 -fsh_sy_h_shappend 2>/dev/null
  2768.  
  2769. # vim:ft=zsh:sw=2:sts=2
  2770.  
  2771.  
  2772. # $1 - PREBUFFER
  2773. # $2 - BUFFER
  2774. #
  2775. function -fast-highlight-string-process {
  2776. local -A pos_to_level level_to_pos pair_map final_pairs
  2777. local input=$1$2 _mybuf=$1$2 __style __quoting
  2778. integer __idx=0 __pair_idx __level=0 __start __end
  2779. local -a match mbegin mend
  2780.  
  2781. pair_map=( "(" ")" "{" "}" "[" "]" )
  2782.  
  2783. while [[ $_mybuf = (#b)[^"{}()[]\\\"'"]#((["({[]})\"'"])|[\\](*))(*) ]]; do
  2784. [[ -n ${match[3]} ]] && {
  2785. __idx+=${mbegin[1]}
  2786.  
  2787. [[ $__quoting = \' ]] && _mybuf=${match[3]} || { _mybuf=${match[3]:1}; (( ++ __idx )); }
  2788. } || {
  2789. __idx+=${mbegin[1]}
  2790. [[ -z $__quoting && -z ${_FAST_COMPLEX_BRACKETS[(r)$((__idx-${#PREBUFFER}-1))]} ]] && {
  2791. if [[ ${match[1]} = ["({["] ]]; then
  2792. pos_to_level[$__idx]=$(( ++__level ))
  2793. level_to_pos[$__level]=$__idx
  2794. elif [[ ${match[1]} = ["]})"] ]]; then
  2795. if (( __level > 0 )); then
  2796. __pair_idx=${level_to_pos[$__level]}
  2797. pos_to_level[$__idx]=$(( __level -- ))
  2798. [[ ${pair_map[${input[__pair_idx]}]} = ${input[__idx]} ]] && {
  2799. final_pairs[$__idx]=$__pair_idx
  2800. final_pairs[$__pair_idx]=$__idx
  2801. }
  2802. else
  2803. pos_to_level[$__idx]=-1
  2804. fi
  2805. fi
  2806. }
  2807.  
  2808. [[ ${match[1]} = \" && $__quoting != \' ]] && { [[ $__quoting = '"' ]] && __quoting="" || __quoting='"'; }
  2809. [[ ${match[1]} = \' && $__quoting != \" ]] && { [[ $__quoting = "'" ]] && __quoting="" || __quoting="'"; }
  2810.  
  2811. _mybuf=${match[4]}
  2812. }
  2813. done
  2814.  
  2815. for __idx in ${(k)pos_to_level}; do
  2816. (( ${+final_pairs[$__idx]} )) && __style=${FAST_THEME_NAME}bracket-level-$(( ( (pos_to_level[$__idx]-1) % 3 ) + 1 )) || __style=${FAST_THEME_NAME}unknown-token
  2817. (( __start=__idx-${#PREBUFFER}-1, __end=__idx-${#PREBUFFER}, __start >= 0 )) && \
  2818. reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}")
  2819. done
  2820.  
  2821. # If cursor is on a bracket, then highlight corresponding bracket, if any.
  2822. if [[ $WIDGET != zle-line-finish ]]; then
  2823. __idx=$(( CURSOR + 1 ))
  2824. if (( ${+pos_to_level[$__idx]} )) && (( ${+final_pairs[$__idx]} )); then
  2825. (( __start=final_pairs[$__idx]-${#PREBUFFER}-1, __end=final_pairs[$__idx]-${#PREBUFFER}, __start >= 0 )) && \
  2826. reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}paired-bracket]}") && \
  2827. reply+=("$CURSOR $__idx ${FAST_HIGHLIGHT_STYLES[${FAST_THEME_NAME}paired-bracket]}")
  2828. fi
  2829. fi
  2830. return 0
  2831. }
  2832.  
  2833.  
  2834. # Standarized way of handling finding plugin dir,
  2835. # regardless of functionargzero and posixargzero,
  2836. # and with an option for a plugin manager to alter
  2837. # the plugin directory (i.e. set ZERO parameter)
  2838. # http://zdharma.org/Zsh-100-Commits-Club/Zsh-Plugin-Standard.html
  2839. 0="${${ZERO:-${0:#$ZSH_ARGZERO}}:-${(%):-%N}}"
  2840. typeset -g FAST_BASE_DIR="${0:h}"
  2841. typeset -ga _FAST_MAIN_CACHE
  2842. # Holds list of indices pointing at brackets that
  2843. # are complex, i.e. e.g. part of "[[" in [[ ... ]]
  2844. typeset -ga _FAST_COMPLEX_BRACKETS
  2845.  
  2846. typeset -g FAST_WORK_DIR
  2847. : ${FAST_WORK_DIR:=$FAST_BASE_DIR}
  2848. FAST_WORK_DIR=${~FAST_WORK_DIR}
  2849.  
  2850. if [[ -z "$ZPLG_CUR_PLUGIN" && "${fpath[(r)$FAST_BASE_DIR]}" != $FAST_BASE_DIR ]]; then
  2851. fpath+=( "$FAST_BASE_DIR" )
  2852. fi
  2853.  
  2854. if [[ "$FAST_WORK_DIR" = /usr/* || ( "$FAST_WORK_DIR" = /opt/* && ! -w "$FAST_WORK_DIR" ) ]]; then
  2855. FAST_WORK_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/fsh"
  2856. command mkdir -p "$FAST_WORK_DIR"
  2857. fi
  2858.  
  2859. # Invokes each highlighter that needs updating.
  2860. # This function is supposed to be called whenever the ZLE state changes.
  2861. _zsh_highlight()
  2862. {
  2863. # Store the previous command return code to restore it whatever happens.
  2864. local ret=$?
  2865.  
  2866. # Remove all highlighting in isearch, so that only the underlining done by zsh itself remains.
  2867. # For details see FAQ entry 'Why does syntax highlighting not work while searching history?'.
  2868. if [[ $WIDGET == zle-isearch-update ]] && ! (( $+ISEARCHMATCH_ACTIVE )); then
  2869. region_highlight=()
  2870. return $ret
  2871. fi
  2872.  
  2873. setopt localoptions warncreateglobal noksharrays noshwordsplit extendedglob typesetsilent nokshglob
  2874. local REPLY # don't leak $REPLY into global scope
  2875. local -a reply
  2876.  
  2877. # Do not highlight if there are more than 300 chars in the buffer. It's most
  2878. # likely a pasted command or a huge list of files in that case..
  2879. [[ -n ${ZSH_HIGHLIGHT_MAXLENGTH:-} ]] && [[ $#BUFFER -gt $ZSH_HIGHLIGHT_MAXLENGTH ]] && return $ret
  2880.  
  2881. # Do not highlight if there are pending inputs (copy/paste).
  2882. [[ $PENDING -gt 0 ]] && return $ret
  2883.  
  2884. # Reset region highlight to build it from scratch
  2885. # may need to remove path_prefix highlighting when the line ends
  2886. if [[ $WIDGET == zle-line-finish ]] || _zsh_highlight_buffer_modified; then
  2887. -fast-highlight-init
  2888. -fast-highlight-process "$PREBUFFER" "$BUFFER" 0
  2889. (( FAST_HIGHLIGHT[use_brackets] )) && {
  2890. _FAST_MAIN_CACHE=( $reply )
  2891. -fast-highlight-string-process "$PREBUFFER" "$BUFFER"
  2892. }
  2893. region_highlight=( $reply )
  2894. else
  2895. local char="${BUFFER[CURSOR+1]}"
  2896. if [[ "$char" = ["{([])}"] || "${FAST_HIGHLIGHT[prev_char]}" = ["{([])}"] ]]; then
  2897. FAST_HIGHLIGHT[prev_char]="$char"
  2898. (( FAST_HIGHLIGHT[use_brackets] )) && {
  2899. reply=( $_FAST_MAIN_CACHE )
  2900. -fast-highlight-string-process "$PREBUFFER" "$BUFFER"
  2901. region_highlight=( $reply )
  2902. }
  2903. fi
  2904. fi
  2905.  
  2906. {
  2907. local cache_place
  2908. local -a region_highlight_copy
  2909.  
  2910. # Re-apply zle_highlight settings
  2911.  
  2912. # region
  2913. if (( REGION_ACTIVE == 1 )); then
  2914. _zsh_highlight_apply_zle_highlight region standout "$MARK" "$CURSOR"
  2915. elif (( REGION_ACTIVE == 2 )); then
  2916. () {
  2917. local needle=$'\n'
  2918. integer min max
  2919. if (( MARK > CURSOR )) ; then
  2920. min=$CURSOR max=$MARK
  2921. else
  2922. min=$MARK max=$CURSOR
  2923. fi
  2924. (( min = ${${BUFFER[1,$min]}[(I)$needle]} ))
  2925. (( max += ${${BUFFER:($max-1)}[(i)$needle]} - 1 ))
  2926. _zsh_highlight_apply_zle_highlight region standout "$min" "$max"
  2927. }
  2928. fi
  2929.  
  2930. # yank / paste (zsh-5.1.1 and newer)
  2931. (( $+YANK_ACTIVE )) && (( YANK_ACTIVE )) && _zsh_highlight_apply_zle_highlight paste standout "$YANK_START" "$YANK_END"
  2932.  
  2933. # isearch
  2934. (( $+ISEARCHMATCH_ACTIVE )) && (( ISEARCHMATCH_ACTIVE )) && _zsh_highlight_apply_zle_highlight isearch underline "$ISEARCHMATCH_START" "$ISEARCHMATCH_END"
  2935.  
  2936. # suffix
  2937. (( $+SUFFIX_ACTIVE )) && (( SUFFIX_ACTIVE )) && _zsh_highlight_apply_zle_highlight suffix bold "$SUFFIX_START" "$SUFFIX_END"
  2938.  
  2939. return $ret
  2940.  
  2941. } always {
  2942. typeset -g _ZSH_HIGHLIGHT_PRIOR_BUFFER="$BUFFER"
  2943. typeset -g _ZSH_HIGHLIGHT_PRIOR_RACTIVE="$REGION_ACTIVE"
  2944. typeset -gi _ZSH_HIGHLIGHT_PRIOR_CURSOR=$CURSOR
  2945. }
  2946. }
  2947.  
  2948. # Apply highlighting based on entries in the zle_highlight array.
  2949. # This function takes four arguments:
  2950. # 1. The exact entry (no patterns) in the zle_highlight array:
  2951. # region, paste, isearch, or suffix
  2952. # 2. The default highlighting that should be applied if the entry is unset
  2953. # 3. and 4. Two integer values describing the beginning and end of the
  2954. # range. The order does not matter.
  2955. _zsh_highlight_apply_zle_highlight() {
  2956. local entry="$1" default="$2"
  2957. integer first="$3" second="$4"
  2958.  
  2959. # read the relevant entry from zle_highlight
  2960. local region="${zle_highlight[(r)${entry}:*]}"
  2961.  
  2962. if [[ -z "$region" ]]; then
  2963. # entry not specified at all, use default value
  2964. region=$default
  2965. else
  2966. # strip prefix
  2967. region="${region#${entry}:}"
  2968.  
  2969. # no highlighting when set to the empty string or to 'none'
  2970. if [[ -z "$region" ]] || [[ "$region" == none ]]; then
  2971. return
  2972. fi
  2973. fi
  2974.  
  2975. integer start end
  2976. if (( first < second )); then
  2977. start=$first end=$second
  2978. else
  2979. start=$second end=$first
  2980. fi
  2981. region_highlight+=("$start $end $region")
  2982. }
  2983.  
  2984.  
  2985. # -------------------------------------------------------------------------------------------------
  2986. # API/utility functions for highlighters
  2987. # -------------------------------------------------------------------------------------------------
  2988.  
  2989. # Whether the command line buffer has been modified or not.
  2990. #
  2991. # Returns 0 if the buffer has changed since _zsh_highlight was last called.
  2992. _zsh_highlight_buffer_modified()
  2993. {
  2994. [[ "${_ZSH_HIGHLIGHT_PRIOR_BUFFER:-}" != "$BUFFER" ]] || [[ "$REGION_ACTIVE" != "$_ZSH_HIGHLIGHT_PRIOR_RACTIVE" ]] || { _zsh_highlight_cursor_moved && [[ "$REGION_ACTIVE" = 1 || "$REGION_ACTIVE" = 2 ]] }
  2995. }
  2996.  
  2997. # Whether the cursor has moved or not.
  2998. #
  2999. # Returns 0 if the cursor has moved since _zsh_highlight was last called.
  3000. _zsh_highlight_cursor_moved()
  3001. {
  3002. [[ -n $CURSOR ]] && [[ -n ${_ZSH_HIGHLIGHT_PRIOR_CURSOR-} ]] && (($_ZSH_HIGHLIGHT_PRIOR_CURSOR != $CURSOR))
  3003. }
  3004.  
  3005. # -------------------------------------------------------------------------------------------------
  3006. # Setup functions
  3007. # -------------------------------------------------------------------------------------------------
  3008.  
  3009. # Helper for _zsh_highlight_bind_widgets
  3010. # $1 is name of widget to call
  3011. _zsh_highlight_call_widget()
  3012. {
  3013. builtin zle "$@" && _zsh_highlight
  3014. }
  3015.  
  3016. # Rebind all ZLE widgets to make them invoke _zsh_highlights.
  3017. _zsh_highlight_bind_widgets()
  3018. {
  3019. setopt localoptions noksharrays
  3020. typeset -F SECONDS
  3021. local prefix=orig-s$SECONDS-r$RANDOM # unique each time, in case we're sourced more than once
  3022.  
  3023. # Load ZSH module zsh/zleparameter, needed to override user defined widgets.
  3024. zmodload zsh/zleparameter 2>/dev/null || {
  3025. print -r -- >&2 'zsh-syntax-highlighting: failed loading zsh/zleparameter.'
  3026. return 1
  3027. }
  3028.  
  3029. # Override ZLE widgets to make them invoke _zsh_highlight.
  3030. local -U widgets_to_bind
  3031. widgets_to_bind=(${${(k)widgets}:#(.*|run-help|which-command|beep|set-local-history|yank)})
  3032.  
  3033. # Always wrap special zle-line-finish widget. This is needed to decide if the
  3034. # current line ends and special highlighting logic needs to be applied.
  3035. # E.g. remove cursor imprint, don't highlight partial paths, ...
  3036. widgets_to_bind+=(zle-line-finish)
  3037.  
  3038. # Always wrap special zle-isearch-update widget to be notified of updates in isearch.
  3039. # This is needed because we need to disable highlighting in that case.
  3040. widgets_to_bind+=(zle-isearch-update)
  3041.  
  3042. local cur_widget
  3043. for cur_widget in $widgets_to_bind; do
  3044. case $widgets[$cur_widget] in
  3045.  
  3046. # Already rebound event: do nothing.
  3047. user:_zsh_highlight_widget_*);;
  3048.  
  3049. # The "eval"'s are required to make $cur_widget a closure: the value of the parameter at function
  3050. # definition time is used.
  3051. #
  3052. # We can't use ${0/_zsh_highlight_widget_} because these widgets are always invoked with
  3053. # NO_function_argzero, regardless of the option's setting here.
  3054.  
  3055. # User defined widget: override and rebind old one with prefix "orig-".
  3056. user:*) zle -N $prefix-$cur_widget ${widgets[$cur_widget]#*:}
  3057. eval "_zsh_highlight_widget_${(q)prefix}-${(q)cur_widget}() { _zsh_highlight_call_widget ${(q)prefix}-${(q)cur_widget} -- \"\$@\" }"
  3058. zle -N $cur_widget _zsh_highlight_widget_$prefix-$cur_widget;;
  3059.  
  3060. # Completion widget: override and rebind old one with prefix "orig-".
  3061. completion:*) zle -C $prefix-$cur_widget ${${(s.:.)widgets[$cur_widget]}[2,3]}
  3062. eval "_zsh_highlight_widget_${(q)prefix}-${(q)cur_widget}() { _zsh_highlight_call_widget ${(q)prefix}-${(q)cur_widget} -- \"\$@\" }"
  3063. zle -N $cur_widget _zsh_highlight_widget_$prefix-$cur_widget;;
  3064.  
  3065. # Builtin widget: override and make it call the builtin ".widget".
  3066. builtin) eval "_zsh_highlight_widget_${(q)prefix}-${(q)cur_widget}() { _zsh_highlight_call_widget .${(q)cur_widget} -- \"\$@\" }"
  3067. zle -N $cur_widget _zsh_highlight_widget_$prefix-$cur_widget;;
  3068.  
  3069. # Incomplete or nonexistent widget: Bind to z-sy-h directly.
  3070. *)
  3071. if [[ $cur_widget == zle-* ]] && [[ -z $widgets[$cur_widget] ]]; then
  3072. _zsh_highlight_widget_${cur_widget}() { :; _zsh_highlight }
  3073. zle -N $cur_widget _zsh_highlight_widget_$cur_widget
  3074. else
  3075. # Default: unhandled case.
  3076. print -r -- >&2 "zsh-syntax-highlighting: unhandled ZLE widget ${(qq)cur_widget}"
  3077. fi
  3078. esac
  3079. done
  3080. }
  3081.  
  3082. # -------------------------------------------------------------------------------------------------
  3083. # Setup
  3084. # -------------------------------------------------------------------------------------------------
  3085.  
  3086. # Try binding widgets.
  3087. _zsh_highlight_bind_widgets || {
  3088. print -r -- >&2 'zsh-syntax-highlighting: failed binding ZLE widgets, exiting.'
  3089. return 1
  3090. }
  3091.  
  3092. # Reset scratch variables when commandline is done.
  3093. _zsh_highlight_preexec_hook()
  3094. {
  3095. typeset -g _ZSH_HIGHLIGHT_PRIOR_BUFFER=
  3096. typeset -gi _ZSH_HIGHLIGHT_PRIOR_CURSOR=0
  3097. typeset -ga _FAST_MAIN_CACHE
  3098. _FAST_MAIN_CACHE=()
  3099. }
  3100.  
  3101. autoload -Uz add-zsh-hook
  3102. add-zsh-hook preexec _zsh_highlight_preexec_hook 2>/dev/null || {
  3103. print -r -- >&2 'zsh-syntax-highlighting: failed loading add-zsh-hook.'
  3104. }
  3105.  
  3106. ZSH_HIGHLIGHT_MAXLENGTH=10000
  3107.  
  3108. # Load zsh/parameter module if available
  3109. zmodload zsh/parameter 2>/dev/null
  3110. zmodload zsh/system 2>/dev/null
  3111.  
  3112. autoload -Uz -- is-at-least fast-theme fast-read-ini-file -fast-run-git-command -fast-make-targets \
  3113. -fast-run-command
  3114. autoload -Uz -- chroma/-git.ch chroma/-example.ch chroma/-grep.ch chroma/-perl.ch chroma/-make.ch \
  3115. chroma/-awk.ch chroma/-vim.ch chroma/-source.ch chroma/-sh.ch chroma/-docker.ch \
  3116. chroma/-autoload.ch chroma/-ssh.ch chroma/-scp.ch chroma/-which.ch chroma/-printf.ch \
  3117. chroma/-ruby.ch chroma/-whatis.ch chroma/-alias.ch chroma/-subcommand.ch \
  3118. chroma/-autorandr.ch chroma/-nmcli.ch chroma/-fast-theme.ch chroma/-node.ch \
  3119. chroma/-fpath_peq.ch
  3120.  
  3121. local __fsyh_theme
  3122. zstyle -s :plugin:fast-syntax-highlighting theme __fsyh_theme
  3123.  
  3124. [[ "${+termcap[Co]}" != 1 || "${termcap[Co]}" != "256" ]] && \
  3125. [[ "${FAST_HIGHLIGHT_STYLES[variable]}" = "fg=113" && "$__fsyh_theme" = default ]] && \
  3126. FAST_HIGHLIGHT_STYLES[variable]="none"
  3127.  
  3128. unset __fsyh_theme
  3129.  
  3130. alias fsh-alias=fast-theme
  3131.  
  3132. -fast-highlight-fill-option-variables
  3133.  
  3134. #====================================================================================================================#
  3135.  
  3136. ## Auto Suggestions ##
  3137.  
  3138. #--------------------------------------------------------------------#
  3139. # Setup #
  3140. #--------------------------------------------------------------------#
  3141.  
  3142. # Precmd hooks for initializing the library and starting pty's
  3143. autoload -Uz add-zsh-hook
  3144.  
  3145. # Asynchronous suggestions are generated in a pty
  3146. zmodload zsh/zpty
  3147.  
  3148. #--------------------------------------------------------------------#
  3149. # Global Configuration Variables #
  3150. #--------------------------------------------------------------------#
  3151.  
  3152. # Color to use when highlighting suggestion
  3153. # Uses format of `region_highlight`
  3154. # More info: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Zle-Widgets
  3155. ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=8'
  3156.  
  3157. # Prefix to use when saving original versions of bound widgets
  3158. ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX=autosuggest-orig-
  3159.  
  3160. ZSH_AUTOSUGGEST_STRATEGY=default
  3161.  
  3162. # Widgets that clear the suggestion
  3163. ZSH_AUTOSUGGEST_CLEAR_WIDGETS=(
  3164. history-search-forward
  3165. history-search-backward
  3166. history-beginning-search-forward
  3167. history-beginning-search-backward
  3168. history-substring-search-up
  3169. history-substring-search-down
  3170. up-line-or-beginning-search
  3171. down-line-or-beginning-search
  3172. up-line-or-history
  3173. down-line-or-history
  3174. accept-line
  3175. )
  3176.  
  3177. # Widgets that accept the entire suggestion
  3178. ZSH_AUTOSUGGEST_ACCEPT_WIDGETS=(
  3179. forward-char
  3180. end-of-line
  3181. vi-forward-char
  3182. vi-end-of-line
  3183. vi-add-eol
  3184. )
  3185.  
  3186. # Widgets that accept the entire suggestion and execute it
  3187. ZSH_AUTOSUGGEST_EXECUTE_WIDGETS=(
  3188. )
  3189.  
  3190. # Widgets that accept the suggestion as far as the cursor moves
  3191. ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS=(
  3192. forward-word
  3193. emacs-forward-word
  3194. vi-forward-word
  3195. vi-forward-word-end
  3196. vi-forward-blank-word
  3197. vi-forward-blank-word-end
  3198. vi-find-next-char
  3199. vi-find-next-char-skip
  3200. )
  3201.  
  3202. # Widgets that should be ignored (globbing supported but must be escaped)
  3203. ZSH_AUTOSUGGEST_IGNORE_WIDGETS=(
  3204. orig-\*
  3205. beep
  3206. run-help
  3207. set-local-history
  3208. which-command
  3209. yank
  3210. yank-pop
  3211. )
  3212.  
  3213. # Max size of buffer to trigger autosuggestion. Leave undefined for no upper bound.
  3214. ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE=
  3215.  
  3216. # Pty name for calculating autosuggestions asynchronously
  3217. ZSH_AUTOSUGGEST_ASYNC_PTY_NAME=zsh_autosuggest_pty
  3218.  
  3219. #--------------------------------------------------------------------#
  3220. # Utility Functions #
  3221. #--------------------------------------------------------------------#
  3222.  
  3223. _zsh_autosuggest_escape_command() {
  3224. setopt localoptions EXTENDED_GLOB
  3225.  
  3226. # Escape special chars in the string (requires EXTENDED_GLOB)
  3227. echo -E "${1//(#m)[\"\'\\()\[\]|*?~]/\\$MATCH}"
  3228. }
  3229.  
  3230. #--------------------------------------------------------------------#
  3231. # Feature Detection #
  3232. #--------------------------------------------------------------------#
  3233.  
  3234. _zsh_autosuggest_feature_detect_zpty_returns_fd() {
  3235. typeset -g _ZSH_AUTOSUGGEST_ZPTY_RETURNS_FD
  3236. typeset -h REPLY
  3237.  
  3238. zpty zsh_autosuggest_feature_detect '{ zshexit() { kill -KILL $$; sleep 1 } }'
  3239.  
  3240. if (( REPLY )); then
  3241. _ZSH_AUTOSUGGEST_ZPTY_RETURNS_FD=1
  3242. else
  3243. _ZSH_AUTOSUGGEST_ZPTY_RETURNS_FD=0
  3244. fi
  3245.  
  3246. zpty -d zsh_autosuggest_feature_detect
  3247. }
  3248.  
  3249. #--------------------------------------------------------------------#
  3250. # Widget Helpers #
  3251. #--------------------------------------------------------------------#
  3252.  
  3253. _zsh_autosuggest_incr_bind_count() {
  3254. if ((${+_ZSH_AUTOSUGGEST_BIND_COUNTS[$1]})); then
  3255. ((_ZSH_AUTOSUGGEST_BIND_COUNTS[$1]++))
  3256. else
  3257. _ZSH_AUTOSUGGEST_BIND_COUNTS[$1]=1
  3258. fi
  3259.  
  3260. typeset -gi bind_count=$_ZSH_AUTOSUGGEST_BIND_COUNTS[$1]
  3261. }
  3262.  
  3263. _zsh_autosuggest_get_bind_count() {
  3264. if ((${+_ZSH_AUTOSUGGEST_BIND_COUNTS[$1]})); then
  3265. typeset -gi bind_count=$_ZSH_AUTOSUGGEST_BIND_COUNTS[$1]
  3266. else
  3267. typeset -gi bind_count=0
  3268. fi
  3269. }
  3270.  
  3271. # Bind a single widget to an autosuggest widget, saving a reference to the original widget
  3272. _zsh_autosuggest_bind_widget() {
  3273. typeset -gA _ZSH_AUTOSUGGEST_BIND_COUNTS
  3274.  
  3275. local widget=$1
  3276. local autosuggest_action=$2
  3277. local prefix=$ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX
  3278.  
  3279. local -i bind_count
  3280.  
  3281. # Save a reference to the original widget
  3282. case $widgets[$widget] in
  3283. # Already bound
  3284. user:_zsh_autosuggest_(bound|orig)_*);;
  3285.  
  3286. # User-defined widget
  3287. user:*)
  3288. _zsh_autosuggest_incr_bind_count $widget
  3289. zle -N $prefix${bind_count}-$widget ${widgets[$widget]#*:}
  3290. ;;
  3291.  
  3292. # Built-in widget
  3293. builtin)
  3294. _zsh_autosuggest_incr_bind_count $widget
  3295. eval "_zsh_autosuggest_orig_${(q)widget}() { zle .${(q)widget} }"
  3296. zle -N $prefix${bind_count}-$widget _zsh_autosuggest_orig_$widget
  3297. ;;
  3298.  
  3299. # Completion widget
  3300. completion:*)
  3301. _zsh_autosuggest_incr_bind_count $widget
  3302. eval "zle -C $prefix${bind_count}-${(q)widget} ${${(s.:.)widgets[$widget]}[2,3]}"
  3303. ;;
  3304. esac
  3305.  
  3306. _zsh_autosuggest_get_bind_count $widget
  3307.  
  3308. # Pass the original widget's name explicitly into the autosuggest
  3309. # function. Use this passed in widget name to call the original
  3310. # widget instead of relying on the $WIDGET variable being set
  3311. # correctly. $WIDGET cannot be trusted because other plugins call
  3312. # zle without the `-w` flag (e.g. `zle self-insert` instead of
  3313. # `zle self-insert -w`).
  3314. eval "_zsh_autosuggest_bound_${bind_count}_${(q)widget}() {
  3315. _zsh_autosuggest_widget_$autosuggest_action $prefix$bind_count-${(q)widget} \$@
  3316. }"
  3317.  
  3318. # Create the bound widget
  3319. zle -N $widget _zsh_autosuggest_bound_${bind_count}_$widget
  3320. }
  3321.  
  3322. # Map all configured widgets to the right autosuggest widgets
  3323. _zsh_autosuggest_bind_widgets() {
  3324. local widget
  3325. local ignore_widgets
  3326.  
  3327. ignore_widgets=(
  3328. .\*
  3329. _\*
  3330. zle-\*
  3331. autosuggest-\*
  3332. $ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX\*
  3333. $ZSH_AUTOSUGGEST_IGNORE_WIDGETS
  3334. )
  3335.  
  3336. # Find every widget we might want to bind and bind it appropriately
  3337. for widget in ${${(f)"$(builtin zle -la)"}:#${(j:|:)~ignore_widgets}}; do
  3338. if [[ -n ${ZSH_AUTOSUGGEST_CLEAR_WIDGETS[(r)$widget]} ]]; then
  3339. _zsh_autosuggest_bind_widget $widget clear
  3340. elif [[ -n ${ZSH_AUTOSUGGEST_ACCEPT_WIDGETS[(r)$widget]} ]]; then
  3341. _zsh_autosuggest_bind_widget $widget accept
  3342. elif [[ -n ${ZSH_AUTOSUGGEST_EXECUTE_WIDGETS[(r)$widget]} ]]; then
  3343. _zsh_autosuggest_bind_widget $widget execute
  3344. elif [[ -n ${ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS[(r)$widget]} ]]; then
  3345. _zsh_autosuggest_bind_widget $widget partial_accept
  3346. else
  3347. # Assume any unspecified widget might modify the buffer
  3348. _zsh_autosuggest_bind_widget $widget modify
  3349. fi
  3350. done
  3351. }
  3352.  
  3353. # Given the name of an original widget and args, invoke it, if it exists
  3354. _zsh_autosuggest_invoke_original_widget() {
  3355. # Do nothing unless called with at least one arg
  3356. (( $# )) || return 0
  3357.  
  3358. local original_widget_name="$1"
  3359.  
  3360. shift
  3361.  
  3362. if (( ${+widgets[$original_widget_name]} )); then
  3363. zle $original_widget_name -- $@
  3364. fi
  3365. }
  3366.  
  3367. #--------------------------------------------------------------------#
  3368. # Highlighting #
  3369. #--------------------------------------------------------------------#
  3370.  
  3371. # If there was a highlight, remove it
  3372. _zsh_autosuggest_highlight_reset() {
  3373. typeset -g _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT
  3374.  
  3375. if [[ -n "$_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT" ]]; then
  3376. region_highlight=("${(@)region_highlight:#$_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT}")
  3377. unset _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT
  3378. fi
  3379. }
  3380.  
  3381. # If there's a suggestion, highlight it
  3382. _zsh_autosuggest_highlight_apply() {
  3383. typeset -g _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT
  3384.  
  3385. if (( $#POSTDISPLAY )); then
  3386. typeset -g _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT="$#BUFFER $(($#BUFFER + $#POSTDISPLAY)) $ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE"
  3387. region_highlight+=("$_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT")
  3388. else
  3389. unset _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT
  3390. fi
  3391. }
  3392.  
  3393. #--------------------------------------------------------------------#
  3394. # Autosuggest Widget Implementations #
  3395. #--------------------------------------------------------------------#
  3396.  
  3397. # Disable suggestions
  3398. _zsh_autosuggest_disable() {
  3399. typeset -g _ZSH_AUTOSUGGEST_DISABLED
  3400. _zsh_autosuggest_clear
  3401. }
  3402.  
  3403. # Enable suggestions
  3404. _zsh_autosuggest_enable() {
  3405. unset _ZSH_AUTOSUGGEST_DISABLED
  3406.  
  3407. if (( $#BUFFER )); then
  3408. _zsh_autosuggest_fetch
  3409. fi
  3410. }
  3411.  
  3412. # Toggle suggestions (enable/disable)
  3413. _zsh_autosuggest_toggle() {
  3414. if [[ -n "${_ZSH_AUTOSUGGEST_DISABLED+x}" ]]; then
  3415. _zsh_autosuggest_enable
  3416. else
  3417. _zsh_autosuggest_disable
  3418. fi
  3419. }
  3420.  
  3421. # Clear the suggestion
  3422. _zsh_autosuggest_clear() {
  3423. # Remove the suggestion
  3424. unset POSTDISPLAY
  3425.  
  3426. _zsh_autosuggest_invoke_original_widget $@
  3427. }
  3428.  
  3429. # Modify the buffer and get a new suggestion
  3430. _zsh_autosuggest_modify() {
  3431. local -i retval
  3432.  
  3433. # Only available in zsh >= 5.4
  3434. local -i KEYS_QUEUED_COUNT
  3435.  
  3436. # Save the contents of the buffer/postdisplay
  3437. local orig_buffer="$BUFFER"
  3438. local orig_postdisplay="$POSTDISPLAY"
  3439.  
  3440. # Clear suggestion while waiting for next one
  3441. unset POSTDISPLAY
  3442.  
  3443. # Original widget may modify the buffer
  3444. _zsh_autosuggest_invoke_original_widget $@
  3445. retval=$?
  3446.  
  3447. # Don't fetch a new suggestion if there's more input to be read immediately
  3448. if (( $PENDING > 0 )) || (( $KEYS_QUEUED_COUNT > 0 )); then
  3449. POSTDISPLAY="$orig_postdisplay"
  3450. return $retval
  3451. fi
  3452.  
  3453. # Optimize if manually typing in the suggestion
  3454. if (( $#BUFFER > $#orig_buffer )); then
  3455. local added=${BUFFER#$orig_buffer}
  3456.  
  3457. # If the string added matches the beginning of the postdisplay
  3458. if [[ "$added" = "${orig_postdisplay:0:$#added}" ]]; then
  3459. POSTDISPLAY="${orig_postdisplay:$#added}"
  3460. return $retval
  3461. fi
  3462. fi
  3463.  
  3464. # Don't fetch a new suggestion if the buffer hasn't changed
  3465. if [[ "$BUFFER" = "$orig_buffer" ]]; then
  3466. POSTDISPLAY="$orig_postdisplay"
  3467. return $retval
  3468. fi
  3469.  
  3470. # Bail out if suggestions are disabled
  3471. if [[ -n "${_ZSH_AUTOSUGGEST_DISABLED+x}" ]]; then
  3472. return $?
  3473. fi
  3474.  
  3475. # Get a new suggestion if the buffer is not empty after modification
  3476. if (( $#BUFFER > 0 )); then
  3477. if [[ -z "$ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE" ]] || (( $#BUFFER <= $ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE )); then
  3478. _zsh_autosuggest_fetch
  3479. fi
  3480. fi
  3481.  
  3482. return $retval
  3483. }
  3484.  
  3485. # Fetch a new suggestion based on what's currently in the buffer
  3486. _zsh_autosuggest_fetch() {
  3487. if zpty -t "$ZSH_AUTOSUGGEST_ASYNC_PTY_NAME" &>/dev/null; then
  3488. _zsh_autosuggest_async_request "$BUFFER"
  3489. else
  3490. local suggestion
  3491. _zsh_autosuggest_strategy_$ZSH_AUTOSUGGEST_STRATEGY "$BUFFER"
  3492. _zsh_autosuggest_suggest "$suggestion"
  3493. fi
  3494. }
  3495.  
  3496. # Offer a suggestion
  3497. _zsh_autosuggest_suggest() {
  3498. local suggestion="$1"
  3499.  
  3500. if [[ -n "$suggestion" ]] && (( $#BUFFER )); then
  3501. POSTDISPLAY="${suggestion#$BUFFER}"
  3502. else
  3503. unset POSTDISPLAY
  3504. fi
  3505. }
  3506.  
  3507. # Accept the entire suggestion
  3508. _zsh_autosuggest_accept() {
  3509. local -i max_cursor_pos=$#BUFFER
  3510.  
  3511. # When vicmd keymap is active, the cursor can't move all the way
  3512. # to the end of the buffer
  3513. if [[ "$KEYMAP" = "vicmd" ]]; then
  3514. max_cursor_pos=$((max_cursor_pos - 1))
  3515. fi
  3516.  
  3517. # Only accept if the cursor is at the end of the buffer
  3518. if [[ $CURSOR = $max_cursor_pos ]]; then
  3519. # Add the suggestion to the buffer
  3520. BUFFER="$BUFFER$POSTDISPLAY"
  3521.  
  3522. # Remove the suggestion
  3523. unset POSTDISPLAY
  3524.  
  3525. # Move the cursor to the end of the buffer
  3526. CURSOR=${#BUFFER}
  3527. fi
  3528.  
  3529. _zsh_autosuggest_invoke_original_widget $@
  3530. }
  3531.  
  3532. # Accept the entire suggestion and execute it
  3533. _zsh_autosuggest_execute() {
  3534. # Add the suggestion to the buffer
  3535. BUFFER="$BUFFER$POSTDISPLAY"
  3536.  
  3537. # Remove the suggestion
  3538. unset POSTDISPLAY
  3539.  
  3540. # Call the original `accept-line` to handle syntax highlighting or
  3541. # other potential custom behavior
  3542. _zsh_autosuggest_invoke_original_widget "accept-line"
  3543. }
  3544.  
  3545. # Partially accept the suggestion
  3546. _zsh_autosuggest_partial_accept() {
  3547. local -i retval cursor_loc
  3548.  
  3549. # Save the contents of the buffer so we can restore later if needed
  3550. local original_buffer="$BUFFER"
  3551.  
  3552. # Temporarily accept the suggestion.
  3553. BUFFER="$BUFFER$POSTDISPLAY"
  3554.  
  3555. # Original widget moves the cursor
  3556. _zsh_autosuggest_invoke_original_widget $@
  3557. retval=$?
  3558.  
  3559. # Normalize cursor location across vi/emacs modes
  3560. cursor_loc=$CURSOR
  3561. if [[ "$KEYMAP" = "vicmd" ]]; then
  3562. cursor_loc=$((cursor_loc + 1))
  3563. fi
  3564.  
  3565. # If we've moved past the end of the original buffer
  3566. if (( $cursor_loc > $#original_buffer )); then
  3567. # Set POSTDISPLAY to text right of the cursor
  3568. POSTDISPLAY="${BUFFER[$(($cursor_loc + 1)),$#BUFFER]}"
  3569.  
  3570. # Clip the buffer at the cursor
  3571. BUFFER="${BUFFER[1,$cursor_loc]}"
  3572. else
  3573. # Restore the original buffer
  3574. BUFFER="$original_buffer"
  3575. fi
  3576.  
  3577. return $retval
  3578. }
  3579.  
  3580. for action in clear modify fetch suggest accept partial_accept execute enable disable toggle; do
  3581. eval "_zsh_autosuggest_widget_$action() {
  3582. local -i retval
  3583. _zsh_autosuggest_highlight_reset
  3584. _zsh_autosuggest_$action \$@
  3585. retval=\$?
  3586. _zsh_autosuggest_highlight_apply
  3587. zle -R
  3588. return \$retval
  3589. }"
  3590. done
  3591.  
  3592. zle -N autosuggest-fetch _zsh_autosuggest_widget_fetch
  3593. zle -N autosuggest-suggest _zsh_autosuggest_widget_suggest
  3594. zle -N autosuggest-accept _zsh_autosuggest_widget_accept
  3595. zle -N autosuggest-clear _zsh_autosuggest_widget_clear
  3596. zle -N autosuggest-execute _zsh_autosuggest_widget_execute
  3597. zle -N autosuggest-enable _zsh_autosuggest_widget_enable
  3598. zle -N autosuggest-disable _zsh_autosuggest_widget_disable
  3599. zle -N autosuggest-toggle _zsh_autosuggest_widget_toggle
  3600.  
  3601. #--------------------------------------------------------------------#
  3602. # Default Suggestion Strategy #
  3603. #--------------------------------------------------------------------#
  3604. # Suggests the most recent history item that matches the given
  3605. # prefix.
  3606. #
  3607.  
  3608. _zsh_autosuggest_strategy_default() {
  3609. # Reset options to defaults and enable LOCAL_OPTIONS
  3610. emulate -L zsh
  3611.  
  3612. # Enable globbing flags so that we can use (#m)
  3613. setopt EXTENDED_GLOB
  3614.  
  3615. # Escape backslashes and all of the glob operators so we can use
  3616. # this string as a pattern to search the $history associative array.
  3617. # - (#m) globbing flag enables setting references for match data
  3618. # TODO: Use (b) flag when we can drop support for zsh older than v5.0.8
  3619. local prefix="${1//(#m)[\\*?[\]<>()|^~#]/\\$MATCH}"
  3620.  
  3621. # Get the history items that match
  3622. # - (r) subscript flag makes the pattern match on values
  3623. typeset -g suggestion="${history[(r)${prefix}*]}"
  3624. }
  3625.  
  3626. #--------------------------------------------------------------------#
  3627. # Match Previous Command Suggestion Strategy #
  3628. #--------------------------------------------------------------------#
  3629. # Suggests the most recent history item that matches the given
  3630. # prefix and whose preceding history item also matches the most
  3631. # recently executed command.
  3632. #
  3633. # For example, suppose your history has the following entries:
  3634. # - pwd
  3635. # - ls foo
  3636. # - ls bar
  3637. # - pwd
  3638. #
  3639. # Given the history list above, when you type 'ls', the suggestion
  3640. # will be 'ls foo' rather than 'ls bar' because your most recently
  3641. # executed command (pwd) was previously followed by 'ls foo'.
  3642. #
  3643. # Note that this strategy won't work as expected with ZSH options that don't
  3644. # preserve the history order such as `HIST_IGNORE_ALL_DUPS` or
  3645. # `HIST_EXPIRE_DUPS_FIRST`.
  3646.  
  3647. _zsh_autosuggest_strategy_match_prev_cmd() {
  3648. # Reset options to defaults and enable LOCAL_OPTIONS
  3649. emulate -L zsh
  3650.  
  3651. # Enable globbing flags so that we can use (#m)
  3652. setopt EXTENDED_GLOB
  3653.  
  3654. # TODO: Use (b) flag when we can drop support for zsh older than v5.0.8
  3655. local prefix="${1//(#m)[\\*?[\]<>()|^~#]/\\$MATCH}"
  3656.  
  3657. # Get all history event numbers that correspond to history
  3658. # entries that match pattern $prefix*
  3659. local history_match_keys
  3660. history_match_keys=(${(k)history[(R)$prefix*]})
  3661.  
  3662. # By default we use the first history number (most recent history entry)
  3663. local histkey="${history_match_keys[1]}"
  3664.  
  3665. # Get the previously executed command
  3666. local prev_cmd="$(_zsh_autosuggest_escape_command "${history[$((HISTCMD-1))]}")"
  3667.  
  3668. # Iterate up to the first 200 history event numbers that match $prefix
  3669. for key in "${(@)history_match_keys[1,200]}"; do
  3670. # Stop if we ran out of history
  3671. [[ $key -gt 1 ]] || break
  3672.  
  3673. # See if the history entry preceding the suggestion matches the
  3674. # previous command, and use it if it does
  3675. if [[ "${history[$((key - 1))]}" == "$prev_cmd" ]]; then
  3676. histkey="$key"
  3677. break
  3678. fi
  3679. done
  3680.  
  3681. # Give back the matched history entry
  3682. typeset -g suggestion="$history[$histkey]"
  3683. }
  3684.  
  3685. #--------------------------------------------------------------------#
  3686. # Async #
  3687. #--------------------------------------------------------------------#
  3688.  
  3689. # Zpty process is spawned running this function
  3690. _zsh_autosuggest_async_server() {
  3691. emulate -R zsh
  3692.  
  3693. # There is a bug in zpty module (fixed in zsh/master) by which a
  3694. # zpty that exits will kill all zpty processes that were forked
  3695. # before it. Here we set up a zsh exit hook to SIGKILL the zpty
  3696. # process immediately, before it has a chance to kill any other
  3697. # zpty processes.
  3698. zshexit() {
  3699. kill -KILL $$
  3700. sleep 1 # Block for long enough for the signal to come through
  3701. }
  3702.  
  3703. # Output only newlines (not carriage return + newline)
  3704. stty -onlcr
  3705.  
  3706. # Silence any error messages
  3707. exec 2>/dev/null
  3708.  
  3709. local last_pid
  3710.  
  3711. while IFS='' read -r -d $'\0' query; do
  3712. # Kill last bg process
  3713. kill -KILL $last_pid &>/dev/null
  3714.  
  3715. # Run suggestion search in the background
  3716. (
  3717. local suggestion
  3718. _zsh_autosuggest_strategy_$ZSH_AUTOSUGGEST_STRATEGY "$query"
  3719. echo -n -E "$suggestion"$'\0'
  3720. ) &
  3721.  
  3722. last_pid=$!
  3723. done
  3724. }
  3725.  
  3726. _zsh_autosuggest_async_request() {
  3727. # Write the query to the zpty process to fetch a suggestion
  3728. zpty -w -n $ZSH_AUTOSUGGEST_ASYNC_PTY_NAME "${1}"$'\0'
  3729. }
  3730.  
  3731. # Called when new data is ready to be read from the pty
  3732. # First arg will be fd ready for reading
  3733. # Second arg will be passed in case of error
  3734. _zsh_autosuggest_async_response() {
  3735. setopt LOCAL_OPTIONS EXTENDED_GLOB
  3736.  
  3737. local suggestion
  3738.  
  3739. zpty -rt $ZSH_AUTOSUGGEST_ASYNC_PTY_NAME suggestion '*'$'\0' 2>/dev/null
  3740. zle autosuggest-suggest -- "${suggestion%%$'\0'##}"
  3741. }
  3742.  
  3743. _zsh_autosuggest_async_pty_create() {
  3744. # With newer versions of zsh, REPLY stores the fd to read from
  3745. typeset -h REPLY
  3746.  
  3747. # If we won't get a fd back from zpty, try to guess it
  3748. if (( ! $_ZSH_AUTOSUGGEST_ZPTY_RETURNS_FD )); then
  3749. integer -l zptyfd
  3750. exec {zptyfd}>&1 # Open a new file descriptor (above 10).
  3751. exec {zptyfd}>&- # Close it so it's free to be used by zpty.
  3752. fi
  3753.  
  3754. # Fork a zpty process running the server function
  3755. zpty -b $ZSH_AUTOSUGGEST_ASYNC_PTY_NAME _zsh_autosuggest_async_server
  3756.  
  3757. # Store the fd so we can remove the handler later
  3758. if (( REPLY )); then
  3759. _ZSH_AUTOSUGGEST_PTY_FD=$REPLY
  3760. else
  3761. _ZSH_AUTOSUGGEST_PTY_FD=$zptyfd
  3762. fi
  3763.  
  3764. # Set up input handler from the zpty
  3765. zle -F $_ZSH_AUTOSUGGEST_PTY_FD _zsh_autosuggest_async_response
  3766. }
  3767.  
  3768. _zsh_autosuggest_async_pty_destroy() {
  3769. # Remove the input handler
  3770. zle -F $_ZSH_AUTOSUGGEST_PTY_FD &>/dev/null
  3771.  
  3772. # Destroy the zpty
  3773. zpty -d $ZSH_AUTOSUGGEST_ASYNC_PTY_NAME &>/dev/null
  3774. }
  3775.  
  3776. _zsh_autosuggest_async_pty_recreate() {
  3777. _zsh_autosuggest_async_pty_destroy
  3778. _zsh_autosuggest_async_pty_create
  3779. }
  3780.  
  3781. _zsh_autosuggest_async_start() {
  3782. typeset -g _ZSH_AUTOSUGGEST_PTY_FD
  3783.  
  3784. _zsh_autosuggest_feature_detect_zpty_returns_fd
  3785. _zsh_autosuggest_async_pty_recreate
  3786.  
  3787. # We recreate the pty to get a fresh list of history events
  3788. add-zsh-hook precmd _zsh_autosuggest_async_pty_recreate
  3789. }
  3790.  
  3791. #--------------------------------------------------------------------#
  3792. # Start #
  3793. #--------------------------------------------------------------------#
  3794.  
  3795. # Start the autosuggestion widgets
  3796. _zsh_autosuggest_start() {
  3797. add-zsh-hook -d precmd _zsh_autosuggest_start
  3798.  
  3799. _zsh_autosuggest_bind_widgets
  3800.  
  3801. # Re-bind widgets on every precmd to ensure we wrap other wrappers.
  3802. # Specifically, highlighting breaks if our widgets are wrapped by
  3803. # zsh-syntax-highlighting widgets. This also allows modifications
  3804. # to the widget list variables to take effect on the next precmd.
  3805. add-zsh-hook precmd _zsh_autosuggest_bind_widgets
  3806.  
  3807. if [[ -n "${ZSH_AUTOSUGGEST_USE_ASYNC+x}" ]]; then
  3808. _zsh_autosuggest_async_start
  3809. fi
  3810. }
  3811.  
  3812. # Start the autosuggestion widgets on the next precmd
  3813. add-zsh-hook precmd _zsh_autosuggest_start
  3814.  
  3815. #====================================================================================================================#
  3816.  
  3817. ## Colored Man Pages ##
  3818.  
  3819. # termcap
  3820. # ks make the keypad send commands
  3821. # ke make the keypad send digits
  3822. # vb emit visual bell
  3823. # mb start blink
  3824. # md start bold
  3825. # me turn off bold, blink and underline
  3826. # so start standout (reverse video)
  3827. # se stop standout
  3828. # us start underline
  3829. # ue stop underline
  3830.  
  3831. function man() {
  3832. env \
  3833. LESS_TERMCAP_mb=$(printf "\e[1;34m") \
  3834. LESS_TERMCAP_md=$(printf "\e[1;34m") \
  3835. LESS_TERMCAP_me=$(printf "\e[0m") \
  3836. LESS_TERMCAP_so=$(printf "\e[1;47;33m") \
  3837. LESS_TERMCAP_se=$(printf "\e[0m") \
  3838. LESS_TERMCAP_us=$(printf "\e[1;32m") \
  3839. LESS_TERMCAP_ue=$(printf "\e[0m") \
  3840. PAGER="${commands[less]:-$PAGER}" \
  3841. man "$@"
  3842. }
  3843.  
  3844. #====================================================================================================================#
  3845.  
  3846. ## Emoticons ##
  3847.  
  3848. export em_confused='¯\_(⊙︿⊙)_/¯'
  3849. export em_crying='ಥ_ಥ'
  3850. export em_cute_bear='ʕ•ᴥ•ʔ'
  3851. export em_cute_face='(。◕‿◕。)'
  3852. export em_excited='☜(⌒▽⌒)☞'
  3853. export em_fisticuffs='ლ(`ー´ლ)'
  3854. export em_fliptable='(╯°□°)╯︵ ┻━┻'
  3855. export em_person_flip_table=$em_fliptable
  3856. export em_person_flip_person='(╯°Д°)╯︵/(.□ . \)\'
  3857. export em_table_flip_person='ノ┬─┬ノ ︵ ( \o°o)\'
  3858. export em_person_unflip_table='┬──┬◡ノ(° -°ノ)'
  3859. export em_happy='ヽ(´▽`)/'
  3860. export em_innocent='ʘ‿ʘ'
  3861. export em_kirby='⊂(◉‿◉)つ'
  3862. export em_lennyface='( ͡° ͜ʖ ͡°)'
  3863. export em_lion='°‿‿°'
  3864. export em_muscleflex='ᕙ(⇀‸↼‶)ᕗ'
  3865. export em_muscleflex2='ᕦ(∩◡∩)ᕤ'
  3866. export em_perky='(`・ω・´)'
  3867. export em_piggy='(´・ω・`)'
  3868. export em_shrug='¯\_(ツ)_/¯'
  3869. export em_point_right='(☞゚ヮ゚)☞'
  3870. export em_point_left='☜(゚ヮ゚☜)'
  3871. export em_magic='╰(•̀ 3 •́)━☆゚.*・。゚'
  3872. export em_shades='(•_•)
  3873. ( •_•)>⌐■-■
  3874. (⌐■_■)'
  3875. export em_disapprove='ಠ_ಠ'
  3876. export em_wink='ಠ‿↼'
  3877. export em_facepalm='(-‸ლ)'
  3878. export em_hataz_gon_hate='ᕕ( ᐛ )ᕗ'
  3879. export em_salute='( ̄^ ̄)ゞ'
  3880.  
  3881. #====================================================================================================================#
  3882.  
  3883. ## Command Not Found Insults ##
  3884.  
  3885. print_message () {
  3886.  
  3887. local messages
  3888. local message
  3889.  
  3890. messages=(
  3891. "Boooo!"
  3892. "Don't you know anything?"
  3893. "RTFM!"
  3894. "Haha, n00b!"
  3895. "Wow! That was impressively wrong!"
  3896. "Pathetic"
  3897. "The worst one today!"
  3898. "n00b alert!"
  3899. "Your application for reduced salary has been sent!"
  3900. "lol"
  3901. "u suk"
  3902. "lol... plz"
  3903. "plz uninstall"
  3904. "And the Darwin Award goes to.... ${USER}!"
  3905. "ERROR_INCOMPETENT_USER"
  3906. "Incompetence is also a form of competence"
  3907. "Bad."
  3908. "Fake it till you make it!"
  3909. "What is this...? Amateur hour!?"
  3910. "Come on! You can do it!"
  3911. "Nice try."
  3912. "What if... you type an actual command the next time!"
  3913. "What if I told you... it is possible to type valid commands."
  3914. "Y u no speak computer???"
  3915. "This is not Windows"
  3916. "Perhaps you should leave the command line alone..."
  3917. "Please step away from the keyboard!"
  3918. "error code: 1D10T"
  3919. "ACHTUNG! ALLES TURISTEN UND NONTEKNISCHEN LOOKENPEEPERS! DAS KOMPUTERMASCHINE IST NICHT FÜR DER GEFINGERPOKEN UND MITTENGRABEN! ODERWISE IST EASY TO SCHNAPPEN DER SPRINGENWERK, BLOWENFUSEN UND POPPENCORKEN MIT SPITZENSPARKEN. IST NICHT FÜR GEWERKEN BEI DUMMKOPFEN. DER RUBBERNECKEN SIGHTSEEREN KEEPEN DAS COTTONPICKEN HÄNDER IN DAS POCKETS MUSS. ZO RELAXEN UND WATSCHEN DER BLINKENLICHTEN."
  3920. "Pro tip: type a valid command!"
  3921. "Go outside."
  3922. "This is not a search engine."
  3923. "(╯°□°)╯︵ ┻━┻"
  3924. "¯\_(ツ)_/¯"
  3925. "So, I'm just going to go ahead and run rm -rf / for you."
  3926. "Why are you so stupid?!"
  3927. "Perhaps computers is not for you..."
  3928. "Why are you doing this to me?!"
  3929. "Don't you have anything better to do?!"
  3930. "I am _seriously_ considering 'rm -rf /'-ing myself..."
  3931. "This is why you get to see your children only once a month."
  3932. "This is why nobody likes you."
  3933. "Are you even trying?!"
  3934. "Try using your brain the next time!"
  3935. "My keyboard is not a touch screen!"
  3936. "Commands, random gibberish, who cares!"
  3937. "Typing incorrect commands, eh?"
  3938. "Are you always this stupid or are you making a special effort today?!"
  3939. "Dropped on your head as a baby, eh?"
  3940. "Brains aren't everything. In your case they're nothing."
  3941. "I don't know what makes you so stupid, but it really works."
  3942. "You are not as bad as people say, you are much, much worse."
  3943. "Two wrongs don't make a right, take your parents as an example."
  3944. "You must have been born on a highway because that's where most accidents happen."
  3945. "If what you don't know can't hurt you, you're invulnerable."
  3946. "If ignorance is bliss, you must be the happiest person on earth."
  3947. "You're proof that god has a sense of humor."
  3948. "Keep trying, someday you'll do something intelligent!"
  3949. "If shit was music, you'd be an orchestra."
  3950. "How many times do I have to flush before you go away?"
  3951. )
  3952.  
  3953. # If CMD_NOT_FOUND_MSGS array is populated use those messages instead of the defaults
  3954. [[ -n ${CMD_NOT_FOUND_MSGS} ]] && messages=( "${CMD_NOT_FOUND_MSGS[@]}" )
  3955.  
  3956. # If CMD_NOT_FOUND_MSGS_APPEND array is populated append those to the existing messages
  3957. [[ -n ${CMD_NOT_FOUND_MSGS_APPEND} ]] && messages+=( "${CMD_NOT_FOUND_MSGS_APPEND[@]}" )
  3958.  
  3959. # Seed RANDOM with an integer of some length
  3960. RANDOM=$(od -vAn -N4 -tu < /dev/urandom)
  3961.  
  3962. # Print a randomly selected message, but only about half the time to annoy the user a
  3963. # little bit less.
  3964. # if [[ $((${RANDOM} % 2)) -lt 1 ]]; then
  3965. # message=${messages[${RANDOM} % ${#messages[@]}]}
  3966. # printf "\n $(tput bold)$(tput setaf 1)${message}$(tput sgr0)\n\n"
  3967. printf "\n $(tput bold)$(tput setaf 1)$(shuf -n 1 -e "${messages[@]}")$(tput sgr0)\n\n"
  3968. #fi
  3969. }
  3970.  
  3971. function_exists () {
  3972. # Zsh returns 0 even on non existing functions with -F so use -f
  3973. declare -f $1 > /dev/null
  3974. return $?
  3975. }
  3976.  
  3977. #
  3978. # The idea below is to copy any existing handlers to another function
  3979. # name and insert the message in front of the old handler in the
  3980. # new handler. By default, neither bash or zsh has has a handler function
  3981. # defined, so the default behaviour is replicated.
  3982. #
  3983. # Also, ensure the handler is only copied once. If we do not ensure this
  3984. # the handler would add itself recursively if this file happens to be
  3985. # sourced multiple times in the same shell, resulting in a neverending
  3986. # stream of messages.
  3987. #
  3988.  
  3989. #
  3990. # Zsh
  3991. #
  3992. if function_exists command_not_found_handler; then
  3993. if ! function_exists orig_command_not_found_handler; then
  3994. eval "orig_$(declare -f command_not_found_handler)"
  3995. fi
  3996. else
  3997. orig_command_not_found_handler () {
  3998. echo "zsh: command not found: $1"
  3999. return 127
  4000. }
  4001. fi
  4002.  
  4003. command_not_found_handler () {
  4004. print_message
  4005. orig_command_not_found_handler "$@"
  4006. }
  4007.  
  4008. #====================================================================================================================#
  4009.  
  4010. ## Hacker Quotes ##
  4011.  
  4012. if [[ -o interactive ]]; then
  4013. hacker_quotes=(
  4014. # Linus Torvalds
  4015. # https://en.wikiquote.org/wiki/Linus_Torvalds
  4016. "Talk is cheap. Show me the code.\n - Linus Torvalds"
  4017. "Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program.\n - Linus Torvalds"
  4018. "I'm an egotistical bastard, and I name all my projects after myself. First Linux, now git.\n - Linus Torvalds"
  4019.  
  4020. # Alan J. Perlis
  4021. # https://en.wikiquote.org/wiki/Alan_Perlis
  4022. "One man's constant is another man's variable.\n - Alan J. Perlis"
  4023. "Functions delay binding; data structures induce binding. Moral: Structure data late in the programming process.\n - Alan J. Perlis"
  4024. "Syntactic sugar causes cancer of the semicolon.\n - Alan J. Perlis"
  4025. "Every program is a part of some other program and rarely fits.\n - Alan J. Perlis"
  4026. "If a program manipulates a large amount of data, it does so in a small number of ways.\n - Alan J. Perlis"
  4027. "Symmetry is a complexity-reducing concept (co-routines include subroutines); seek it everywhere.\n - Alan J. Perlis"
  4028. "It is easier to write an incorrect program than understand a correct one.\n - Alan J. Perlis"
  4029. "A programming language is low level when its programs require attention to the irrelevant.\n - Alan J. Perlis"
  4030. "It is better to have 100 functions operate on one data structure than 10 functions on 10 data structures.\n - Alan J. Perlis"
  4031. "Get into a rut early: Do the same process the same way. Accumulate idioms. Standardize. The only difference(!) between Shakespeare and you was the size of his idiom list - not the size of his vocabulary.\n - Alan J. Perlis"
  4032. "If you have a procedure with ten parameters, you probably missed some.\n - Alan J. Perlis"
  4033. "Recursion is the root of computation since it trades description for time.\n - Alan J. Perlis"
  4034. "If two people write exactly the same program, each should be put into microcode and then they certainly won't be the same.\n - Alan J. Perlis"
  4035. "In the long run every program becomes rococo - then rubble.\n - Alan J. Perlis"
  4036. "Everything should be built top-down, except the first time.\n - Alan J. Perlis"
  4037. "Every program has (at least) two purposes: the one for which it was written, and another for which it wasn't.\n - Alan J. Perlis"
  4038. "If a listener nods his head when you're explaining your program, wake him up.\n - Alan J. Perlis"
  4039. "A program without a loop and a structured variable isn't worth writing.\n - Alan J. Perlis"
  4040. "A language that doesn't affect the way you think about programming, is not worth knowing.\n - Alan J. Perlis"
  4041. "Wherever there is modularity there is the potential for misunderstanding: Hiding information implies a need to check communication.\n - Alan J. Perlis"
  4042. "Optimization hinders evolution.\n - Alan J. Perlis"
  4043. "A good system can't have a weak command language.\n - Alan J. Perlis"
  4044. "To understand a program you must become both the machine and the program.\n - Alan J. Perlis"
  4045. "Perhaps if we wrote programs from childhood on, as adults we'd be able to read them.\n - Alan J. Perlis"
  4046. "One can only display complex information in the mind. Like seeing, movement or flow or alteration of view is more important than the static picture, no matter how lovely.\n - Alan J. Perlis"
  4047. "There will always be things we wish to say in our programs that in all known languages can only be said poorly.\n - Alan J. Perlis"
  4048. "Once you understand how to write a program get someone else to write it.\n - Alan J. Perlis"
  4049. "Around computers it is difficult to find the correct unit of time to measure progress. Some cathedrals took a century to complete. Can you imagine the grandeur and scope of a program that would take as long?\n - Alan J. Perlis"
  4050. "For systems, the analogue of a face-lift is to add to the control graph an edge that creates a cycle, not just an additional node.\n - Alan J. Perlis"
  4051. "In programming, everything we do is a special case of something more general -- and often we know it too quickly.\n - Alan J. Perlis"
  4052. "Simplicity does not precede complexity, but follows it.\n - Alan J. Perlis"
  4053. "Programmers are not to be measured by their ingenuity and their logic but by the completeness of their case analysis.\n - Alan J. Perlis"
  4054. "The eleventh commandment was \"Thou Shalt Compute\" or \"Thou Shalt Not Compute\" - I forget which.\n - Alan J. Perlis"
  4055. "The string is a stark data structure and everywhere it is passed there is much duplication of process. It is a perfect vehicle for hiding information.\n - Alan J. Perlis"
  4056. "Everyone can be taught to sculpt: Michelangelo would have had to be taught not to. So it is with great programmers.\n - Alan J. Perlis"
  4057. "The use of a program to prove the 4-color theorem will not change mathematics - it merely demonstrates that the theorem, a challenge for a century, is probably not important to mathematics.\n - Alan J. Perlis"
  4058. "The most important computer is the one that rages in our skulls and ever seeks that satisfactory external emulator. The standarization of real computers would be a disaster - and so it probably won't happen.\n - Alan J. Perlis"
  4059. "Structured Programming supports the law of the excluded middle.\n - Alan J. Perlis"
  4060. "Re graphics: A picture is worth 10K words - but only those to describe the picture. Hardly any sets of 10K words can be adequately described with pictures.\n - Alan J. Perlis"
  4061. "There are two ways to write error-free programs; only the third one works.\n - Alan J. Perlis"
  4062. "Some programming languages manage to absorb change, but withstand progress.\n - Alan J. Perlis"
  4063. "You can measure a programmer's perspective by noting his attitude on the continuing vitality of FORTRAN.\n - Alan J. Perlis"
  4064. "In software systems, it is often the early bird that makes the worm.\n - Alan J. Perlis"
  4065. "Sometimes I think the only universal in the computing field is the fetch-execute cycle.\n - Alan J. Perlis"
  4066. "The goal of computation is the emulation of our synthetic abilities, not the understanding of our analytic ones.\n - Alan J. Perlis"
  4067. "Like punning, programming is a play on words.\n - Alan J. Perlis"
  4068. "As Will Rogers would have said, \"There is no such thing as a free variable.\"\n - Alan J. Perlis"
  4069. "The best book on programming for the layman is \"Alice in Wonderland\"; but that's because it's the best book on anything for the layman.\n - Alan J. Perlis"
  4070. "Giving up on assembly language was the apple in our Garden of Eden: Languages whose use squanders machine cycles are sinful. The LISP machine now permits LISP programmers to abandon bra and fig-leaf.\n - Alan J. Perlis"
  4071. "When we understand knowledge-based systems, it will be as before -- except our fingertips will have been singed.\n - Alan J. Perlis"
  4072. "Bringing computers into the home won't change either one, but may revitalize the corner saloon.\n - Alan J. Perlis"
  4073. "Systems have sub-systems and sub-systems have sub- systems and so on ad infinitum - which is why we're always starting over.\n - Alan J. Perlis"
  4074. "So many good ideas are never heard from again once they embark in a voyage on the semantic gulf.\n - Alan J. Perlis"
  4075. "Beware of the Turing tar-pit in which everything is possible but nothing of interest is easy.\n - Alan J. Perlis"
  4076. "A LISP programmer knows the value of everything, but the cost of nothing.\n - Alan J. Perlis"
  4077. "Software is under a constant tension. Being symbolic it is arbitrarily perfectible; but also it is arbitrarily changeable.\n - Alan J. Perlis"
  4078. "It is easier to change the specification to fit the program than vice versa.\n - Alan J. Perlis"
  4079. "Fools ignore complexity. Pragmatists suffer it. Some can avoid it. Geniuses remove it.\n - Alan J. Perlis"
  4080. "In English every word can be verbed. Would that it were so in our programming languages.\n - Alan J. Perlis"
  4081. "In seeking the unattainable, simplicity only gets in the way.\n - Alan J. Perlis"
  4082. "In programming, as in everything else, to be in error is to be reborn.\n - Alan J. Perlis"
  4083. "In computing, invariants are ephemeral.\n - Alan J. Perlis"
  4084. "When we write programs that \"learn\", it turns out that we do and they don't.\n - Alan J. Perlis"
  4085. "Often it is the means that justify the ends: Goals advance technique and technique survives even when goal structures crumble.\n - Alan J. Perlis"
  4086. "Make no mistake about it: Computers process numbers - not symbols. We measure our understanding (and control) by the extent to which we can arithmetize an activity.\n - Alan J. Perlis"
  4087. "Making something variable is easy. Controlling duration of constancy is the trick.\n - Alan J. Perlis"
  4088. "Think of all the psychic energy expended in seeking a fundamental distinction between \"algorithm\" and \"program\".\n - Alan J. Perlis"
  4089. "If we believe in data structures, we must believe in independent (hence simultaneous) processing. For why else would we collect items within a structure? Why do we tolerate languages that give us the one without the other?\n - Alan J. Perlis"
  4090. "In a 5 year period we get one superb programming language. Only we can't control when the 5 year period will be.\n - Alan J. Perlis"
  4091. "Over the centuries the Indians developed sign language for communicating phenomena of interest. Programmers from different tribes (FORTRAN, LISP, ALGOL, SNOBOL, etc.) could use one that doesn't require them to carry a blackboard on their ponies.\n - Alan J. Perlis"
  4092. "Documentation is like term insurance: It satisfies because almost no one who subscribes to it depends on its benefits.\n - Alan J. Perlis"
  4093. "An adequate bootstrap is a contradiction in terms.\n - Alan J. Perlis"
  4094. "It is not a language's weakness but its strengths that control the gradient of its change: Alas, a language never escapes its embryonic sac.\n - Alan J. Perlis"
  4095. "Is it possible that software is not like anything else, that it is meant to be discarded: that the whole point is to see it as a soap bubble?\n - Alan J. Perlis"
  4096. "Because of its vitality, the computing field is always in desperate need of new cliches: Banality soothes our nerves.\n - Alan J. Perlis"
  4097. "It is the user who should parameterize procedures, not their creators.\n - Alan J. Perlis"
  4098. "The cybernetic exchange between man, computer and algorithm is like a game of musical chairs: The frantic search for balance always leaves one of the three standing ill at ease.\n - Alan J. Perlis"
  4099. "If your computer speaks English, it was probably made in Japan.\n - Alan J. Perlis"
  4100. "A year spent in artificial intelligence is enough to make one believe in God.\n - Alan J. Perlis"
  4101. "Prolonged contact with the computer turns mathematicians into clerks and vice versa.\n - Alan J. Perlis"
  4102. "In computing, turning the obvious into the useful is a living definition of the word \"frustration\".\n - Alan J. Perlis"
  4103. "We are on the verge: Today our program proved Fermat's next-to-last theorem.\n - Alan J. Perlis"
  4104. "What is the difference between a Turing machine and the modern computer? It's the same as that between Hillary's ascent of Everest and the establishment of a Hilton hotel on its peak.\n - Alan J. Perlis"
  4105. "Motto for a research laboratory: What we work on today, others will first think of tomorrow.\n - Alan J. Perlis"
  4106. "Though the Chinese should adore APL, it's FORTRAN they put their money on.\n - Alan J. Perlis"
  4107. "We kid ourselves if we think that the ratio of procedure to data in an active data-base system can be made arbitrarily small or even kept small.\n - Alan J. Perlis"
  4108. "We have the mini and the micro computer. In what semantic niche would the pico computer fall?\n - Alan J. Perlis"
  4109. "It is not the computer's fault that Maxwell's equations are not adequate to design the electric motor.\n - Alan J. Perlis"
  4110. "One does not learn computing by using a hand calculator, but one can forget arithmetic.\n - Alan J. Perlis"
  4111. "Computation has made the tree flower.\n - Alan J. Perlis"
  4112. "The computer reminds one of Lon Chaney -- it is the machine of a thousand faces.\n - Alan J. Perlis"
  4113. "The computer is the ultimate polluter: its feces are indistinguish- able from the food it produces.\n - Alan J. Perlis"
  4114. "When someone says \"I want a programming language in which I need only say what I wish done,\" give him a lollipop.\n - Alan J. Perlis"
  4115. "Interfaces keep things tidy, but don't accelerate growth: Functions do.\n - Alan J. Perlis"
  4116. "Don't have good ideas if you aren't willing to be responsible for them.\n - Alan J. Perlis"
  4117. "Computers don't introduce order anywhere as much as they expose opportunities.\n - Alan J. Perlis"
  4118. "When a professor insists computer science is X but not Y, have compassion for his graduate students.\n - Alan J. Perlis"
  4119. "In computing, the mean time to failure keeps getting shorter.\n - Alan J. Perlis"
  4120. "In man-machine symbiosis, it is man who must adjust: The machines can't.\n - Alan J. Perlis"
  4121. "We will never run out of things to program as long as there is a single program around.\n - Alan J. Perlis"
  4122. "Dealing with failure is easy: Work hard to improve. Success is also easy to handle: You've solved the wrong problem. Work hard to improve.\n - Alan J. Perlis"
  4123. "One can't proceed from the informal to the formal by formal means.\n - Alan J. Perlis"
  4124. "Purely applicative languages are poorly applicable.\n - Alan J. Perlis"
  4125. "The proof of a system's value is its existence.\n - Alan J. Perlis"
  4126. "You can't communicate complexity, only an awareness of it.\n - Alan J. Perlis"
  4127. "It's difficult to extract sense from strings, but they're the only communication coin we can count on.\n - Alan J. Perlis"
  4128. "The debate rages on: is PL/I Bachtrian or Dromedary?\n - Alan J. Perlis"
  4129. "Whenever two programmers meet to criticize their programs, both are silent.\n - Alan J. Perlis"
  4130. "Think of it! With VLSI we can pack 100 ENIACS in 1 sq. cm.\n - Alan J. Perlis"
  4131. "Editing is a rewording activity.\n - Alan J. Perlis"
  4132. "Why did the Roman Empire collapse? What is Latin for office automation?\n - Alan J. Perlis"
  4133. "Computer Science is embarrassed by the computer.\n - Alan J. Perlis"
  4134. "The only constructive theory connecting neuroscience and psychology will arise from the study of software.\n - Alan J. Perlis"
  4135. "Within a computer natural language is unnatural.\n - Alan J. Perlis"
  4136. "Most people find the concept of programming obvious, but the doing impossible.\n - Alan J. Perlis"
  4137. "You think you know when you can learn, are more sure when you can write, even more when you can teach, but certain when you can program.\n - Alan J. Perlis"
  4138. "It goes against the grain of modern education to teach children to program. What fun is there in making plans, acquiring discipline in organizing thoughts, devoting attention to detail and learning to be self-critical?\n - Alan J. Perlis"
  4139. "If you can imagine a society in which the computer- robot is the only menial, you can imagine anything.\n - Alan J. Perlis"
  4140. "Programming is an unnatural act.\n - Alan J. Perlis"
  4141. "Adapting old programs to fit new machines usually means adapting new machines to behave like old ones.\n - Alan J. Perlis"
  4142.  
  4143. # Donald E. Knuth
  4144. # https://en.wikiquote.org/wiki/Donald_Knuth
  4145. "Beware of bugs in the above code; I have only proved it correct, not tried it.\n - Donald E. Knuth"
  4146. "Science is knowledge which we understand so well that we can teach it to a computer; and if we don't fully understand something, it is an art to deal with it.\n - Donald E. Knuth"
  4147. "In fact, my main conclusion after spending ten years of my life working on the TEX project is that software is hard. It’s harder than anything else I’ve ever had to do.\n - Donald E. Knuth"
  4148. "Let us change our traditional attitude to the construction of programs: Instead of imagining that our main task is to instruct a computer what to do, let us concentrate rather on explaining to human beings what we want a computer to do.\n - Donald E. Knuth"
  4149. "The real problem is that programmers have spent far too much time worrying about efficiency in the wrong places and at the wrong times; premature optimization is the root of all evil (or at least most of it) in programming.\n - Donald E. Knuth"
  4150.  
  4151. # Edsger W. Dijkstra
  4152. # https://en.wikiquote.org/wiki/Edsger_W._Dijkstra
  4153. "Testing shows the presence, not the absence of bugs.\n - Edsger W. Dijkstra"
  4154. "The competent programmer is fully aware of the strictly limited size of his own skull; therefore he approaches the programming task in full humility, and among other things he avoids clever tricks like the plague.\n - Edsger W. Dijkstra"
  4155. "LISP has been jokingly described as \"the most intelligent way to misuse a computer\". I think that description a great compliment because it transmits the full flavor of liberation: it has assisted a number of our most gifted fellow humans in thinking previously impossible thoughts.\n - Edsger W. Dijkstra"
  4156. "Besides a mathematical inclination, an exceptionally good mastery of one's native tongue is the most vital asset of a competent programmer.\n - Edsger W. Dijkstra"
  4157. "Simplicity is a great virtue but it requires hard work to achieve it and education to appreciate it. And to make matters worse: complexity sells better.\n - Edsger W. Dijkstra"
  4158. "My point today is that, if we wish to count lines of code, we should not regard them as \"lines produced\" but as \"lines spent\": the current conventional wisdom is so foolish as to book that count on the wrong side of the ledger.\n - Edsger W. Dijkstra"
  4159.  
  4160. # Richard Stallmon
  4161. "I'd just like to interject for a moment. What you’re referring to as Linux, is in fact, GNU/Linux, or as I’ve recently taken to calling it, GNU plus Linux. Linux is not an operating system unto itself, but rather another free component of a fully functioning GNU system made useful by the GNU corelibs, shell utilities and vital system components comprising a full OS as defined by POSIX. Many computer users run a modified version of the GNU system every day, without realizing it. Through a peculiar turn of events, the version of GNU which is widely used today is often called “Linux”, and many of its users are not aware that it is basically the GNU system, developed by the GNU Project. There really is a Linux, and these people are using it, but it is just a part of the system they use. Linux is the kernel: the program in the system that allocates the machine’s resources to the other programs that you run. The kernel is an essential part of an operating system, but useless by itself; it can only function in the context of a complete operating system. Linux is normally used in combination with the GNU operating system: the whole system is basically GNU with Linux added, or GNU/Linux. All the so-called “Linux” distributions are really distributions of GNU/Linux.\n - Richard Stallmon"
  4162.  
  4163. # mics
  4164. "There are two ways of constructing a software design. One way is to make it so simple that there are obviously no deficiencies. And the other way is to make it so complicated that there are no obvious deficiencies.\n - C.A.R. Hoare"
  4165. "There are only two hard things in Computer Science: cache invalidation and naming things.\n - Phil Karlton"
  4166. "Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.\n - Martin Golding"
  4167. "The trouble with programmers is that you can never tell what a programmer is doing until it’s too late.\n - Seymour Cray"
  4168. "First learn computer science and all the theory. Next develop a programming style. Then forget all that and just hack.\n - George Carrette"
  4169. "Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.\n - Brian W. Kernighan"
  4170. "Measuring programming progress by lines of code is like measuring aircraft building progress by weight.\n - Bill Gates"
  4171. "The best programmers are not marginally better than merely good ones. They are an order-of-magnitude better, measured by whatever standard: conceptual creativity, speed, ingenuity of design, or problem-solving ability.\n - Randall E. Stross"
  4172. "For a long time it puzzled me how something so expensive, so leading edge, could be so useless. And then it occurred to me that a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are, in short, a perfect match.\n - Bill Bryson"
  4173. "You can’t have great software without a great team, and most software teams behave like dysfunctional families.\n - Jim McCarthy"
  4174. "Incorrect documentation is often worse than no documentation.\n - Bertrand Meyer"
  4175. "Correctness is clearly the prime quality. If a system does not do what it is supposed to do, then everything else about it matters little.\n - Bertrand Meyer"
  4176. "I would love to change the world, but they won't give me the source code.\n - Anonymous"
  4177. "Any fool can write code that a computer can understand. Good programmers write code that humans can understand.\n - Martin Fowler"
  4178. "I am not a great programmer; I am just a good programmer with great habits.\n - Kent Beck"
  4179. "A Computer is a state machine. Threads are for people who can't program state machines.\n - Alan Cox"
  4180. "Not everything worth doing is worth doing well.\n - Tom West"
  4181. "Peace comes from thinking.\n - N.S.A"
  4182. )
  4183. echo "${hacker_quotes[RANDOM % #hacker_quotes + 1]}"
  4184. echo
  4185. # release memory
  4186. unset hacker_quotes
  4187. fi
  4188.  
  4189. #====================================================================================================================#
  4190.  
  4191.  
  4192. ######################################################################################################################
  4193.  
  4194. ### Aliases ###
  4195.  
  4196. ## files and directories
  4197.  
  4198. # trash
  4199. alias trash="~/.local/share/Trash/files"
  4200.  
  4201. #====================================================================================================================#
  4202.  
  4203. ## shorter commands
  4204.  
  4205. # clear
  4206. alias c="clear"
  4207.  
  4208. # man
  4209. alias m="man"
  4210.  
  4211. # list
  4212. alias l="ls"
  4213.  
  4214. # grep
  4215. alias g="grep"
  4216.  
  4217. # list and grep
  4218. alias lg="ls | grep"
  4219.  
  4220. # list all
  4221. alias la="ls -a"
  4222.  
  4223. # list long
  4224. alias ll="ls -l"
  4225.  
  4226. # list recursively
  4227. alias lR="ls -R"
  4228.  
  4229. # get pid ID of a process
  4230. alias getpid="ps ax | grep"
  4231.  
  4232. # check aliases
  4233. alias falias="cat /home/user/.zsh | grep alias"
  4234.  
  4235. # exit
  4236. alias e="exit"
  4237.  
  4238. # start tmux
  4239. alias t="tmux"
  4240.  
  4241. #====================================================================================================================#
  4242.  
  4243. ## package management
  4244.  
  4245. # install
  4246. alias install="sudo apt install --no-install-recommends"
  4247.  
  4248. # install from backport
  4249. alias install-backport="sudo apt -t stretch-backports install --no-install-recommends"
  4250.  
  4251. # update
  4252. alias update="sudo apt update"
  4253.  
  4254. # upgrade
  4255. alias upgrade="sudo apt upgrade"
  4256.  
  4257. # remove uneeded dependencies
  4258. alias autoremove="sudo apt autoremove"
  4259.  
  4260. # fix broken packages
  4261. alias apt-fix="sudo apt update --fix-missing"
  4262.  
  4263. # mark a package as manually installed
  4264. alias mark-manual="sudo apt-mark manual"
  4265.  
  4266. # mark a package as automatically installed
  4267. alias mark-auto="sudo apt-mark auto"
  4268.  
  4269. # search for a package
  4270. alias apt-search="sudo apt-cache search"
  4271.  
  4272. # search for a package in backport
  4273. alias apt-search-backport="sudo apt-cache search -t stretch-backports"
  4274.  
  4275. # uninstall a package
  4276. alias uninstall="sudo apt remove"
  4277.  
  4278. #====================================================================================================================#
  4279.  
  4280. ## system functions
  4281.  
  4282. # reboot
  4283. alias reboot="/sbin/reboot"
  4284.  
  4285. # shutdown
  4286. alias shutdown="/sbin/shutdown"
  4287.  
  4288. # poweroff
  4289. alias poweroff="/sbin/poweroff"
  4290.  
  4291. #====================================================================================================================#
  4292.  
  4293. ## quicker editing
  4294.  
  4295. # zsh config
  4296. alias .zsh="nvim /home/user/.zsh"
  4297.  
  4298. # add WiFi
  4299. alias wifi="doas nvim /etc/hostname.iwn0"
  4300.  
  4301. # .Xresources
  4302. alias .Xresources="nvim /home/user/.Xresources"
  4303.  
  4304. # .xsession
  4305. alias .xsession="nvim /home/user/.xsession"
  4306.  
  4307. #====================================================================================================================#
  4308.  
  4309. ######################################################################################################################
  4310.  
  4311. ### Prompt ###
  4312.  
  4313. ## smiley prompt
  4314. $Smilies
  4315. setopt PROMPT_SUBST
  4316. prompt_status_smiley() {
  4317. [[ $? -ne 0 ]] && echo '%F{1}):%f'
  4318. }
  4319.  
  4320. RPROMPT='$(prompt_status_smiley)'
  4321. PS2=$' \e[0;34m%}%B>%{\e[0m%}%b'
  4322.  
  4323. ## main prompt
  4324. if [[ $BENDER_THEME_STYLE == "mini" ]] ; then
  4325. local user_host_jobs=
  4326. else
  4327. local user_host_jobs='[ %F{white}%n%F{red} :: %F{yellow}%m%F{red} ]-( %F{white}%j%F{red} )-'
  4328. fi
  4329.  
  4330. PROMPT='
  4331. %B%F{red}┌───=${user_host_jobs}[ %F{white}%~%F{red} ]$(git_prompt_info)
  4332. └──(%b%f '
  4333.  
  4334. ZSH_THEME_GIT_PROMPT_PREFIX="-( %F{blue}"
  4335. ZSH_THEME_GIT_PROMPT_SUFFIX="%F{red} )"
  4336.  
  4337. ######################################################################################################################
  4338.  
  4339. ============================================================================================================================
  4340.  
  4341. ## htop
  4342.  
  4343. #####################
  4344. #
  4345. # htoprc
  4346. #
  4347. #####################
  4348.  
  4349. fields=0 48 17 18 38 39 2 46 47 49 1
  4350. sort_key=46
  4351. sort_direction=1
  4352. hide_threads=0
  4353. hide_kernel_threads=0
  4354. hide_userland_threads=0
  4355. shadow_other_users=0
  4356. show_thread_names=1
  4357. show_program_path=1
  4358. highlight_base_name=1
  4359. highlight_megabytes=1
  4360. highlight_threads=1
  4361. tree_view=1
  4362. header_margin=0
  4363. detailed_cpu_time=1
  4364. cpu_count_from_zero=1
  4365. update_process_names=1
  4366. account_guest_in_cpu_meter=1
  4367. color_scheme=0
  4368. delay=15
  4369. left_meters=AllCPUs Memory Swap
  4370. left_meter_modes=1 1 1
  4371. right_meters=Hostname Clock Tasks LoadAverage Uptime
  4372. right_meter_modes=2 2 2 2 2
  4373.  
  4374. ============================================================================================================================
  4375.  
  4376. ## neovim
  4377.  
  4378. """""""""""""""""""""
  4379. "
  4380. " Neovim Config
  4381. "
  4382. """""""""""""""""""""
  4383.  
  4384. """ Global Settings
  4385.  
  4386. " enter the current millenium
  4387. set nocompatible
  4388.  
  4389. " highlight matching characters
  4390. set showmatch
  4391.  
  4392. " enable folding
  4393. set foldenable
  4394.  
  4395. " open most folds by default
  4396. set foldlevelstart=10
  4397.  
  4398. " 10 nested fold max
  4399. set foldnestmax=10
  4400.  
  4401. " fold based on indent level
  4402. set foldmethod=indent
  4403.  
  4404. " highlight search
  4405. set hlsearch
  4406.  
  4407. " set incremental search
  4408. set incsearch
  4409.  
  4410. " ingore cases in search
  4411. set ignorecase
  4412. set smartcase
  4413.  
  4414. " disable swap file creation
  4415. set noswapfile
  4416.  
  4417. " enable syntax
  4418. syntax enable
  4419. syntax on
  4420.  
  4421. " enable plugins for netrw
  4422. filetype plugin on
  4423.  
  4424. " enable numbers
  4425. set number
  4426. set relativenumber
  4427.  
  4428. " filetype detection
  4429. filetype plugin indent on
  4430.  
  4431. " replace ~ with a space
  4432. set fcs=eob:\
  4433.  
  4434. " list chars
  4435. :set listchars=tab:\|\
  4436. :set list
  4437.  
  4438. " turn on cursor line highlighting
  4439. set cursorline
  4440. " search down into subfolders and provide tab-completion for all file-related tasks
  4441. set path+=**
  4442.  
  4443. " display all matching files when using tab completion
  4444. set wildmenu
  4445.  
  4446. "" - Hit tab to :find by partial match
  4447. "" - Use * to make it fuzzy
  4448. "" - :b lets you autocomplete any open buffer
  4449.  
  4450. " Create the `tags` file (need to create a `tags` file)
  4451. command! MakeTags !ctags -R .
  4452.  
  4453. "" - Use ^] to jump to tag under cursor
  4454. "" - Use g^] for ambiguous tags
  4455. "" - Use ^t to jump back up the tag stack
  4456.  
  4457. " autocomplete notes
  4458. "" - ^x^n for JUST this file
  4459. "" - ^x^f for filenames (works with our path trick!)
  4460. "" - ^x^] for tags only
  4461. "" - ^n for anything specified by the 'complete' option
  4462. "" - Use ^n and ^p to go back and forth in the suggestion list
  4463.  
  4464. " file browsing
  4465. "" Tweaks for browsing
  4466. let g:netrw_banner=0 " disable annoying banner
  4467. let g:netrw_browse_split=4 " open in prior window
  4468. let g:netrw_altv=1 " open splits to the right
  4469. let g:netrw_liststyle=3 " tree view
  4470. let g:netrw_winsize = 25 " set window size
  4471. let g:netrw_list_hide=netrw_gitignore#Hide()
  4472. let g:netrw_list_hide.=',\(^\|\s\s\)\zs\.\S\+'
  4473.  
  4474. "" - :edit a folder to open a file browser
  4475. "" - <CR>/v/t to open in an h-split/v-split/tab
  4476. "" - check |netrw-browse-maps| for more mappings
  4477.  
  4478. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  4479.  
  4480. """ Cursor
  4481.  
  4482. :set guicursor=n-v-c:hor20,i-ci-ve:ver25,r-cr:hor20,o:hor50
  4483. \,a:blinkwait700-blinkoff400-blinkon250-Cursor/lCursor
  4484. \,sm:block-blinkwait175-blinkoff150-blinkon175
  4485. let $NVIM_TUI_ENABLE_CURSOR_SHAPE = 0
  4486.  
  4487. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  4488.  
  4489. """ Keybindings
  4490.  
  4491. " source init.vim
  4492. map <F5> :source ~/.config/nvim/init.vim<CR>
  4493.  
  4494. " enable spell check
  4495. map <M-c> :set spell spelllang=en_us<CR>
  4496.  
  4497. " split veritcally
  4498. map <M-v> :vsplit<CR>
  4499.  
  4500. " split horizontally
  4501. map <M-h> :split<CR>
  4502.  
  4503. " file browsing
  4504. map <M-l> :Vexplore<CR>
  4505.  
  4506. " open a terminal window
  4507. map <M-t> :tabnew +terminal<CR>
  4508.  
  4509. " space open/closes folds
  4510. map <space> za<CR>
  4511.  
  4512. " copy to system keyboard
  4513. vnoremap <M-y> "+y
  4514.  
  4515. " paste from system keyboard
  4516. vnoremap <M-p> "*p
  4517.  
  4518. " unbind up arrow key
  4519. "inoremap <up> <nop>
  4520. "vnoremap <up> <nop>
  4521.  
  4522. " unbind down arrow key
  4523. "inoremap <down> <nop>
  4524. "vnoremap <down> <nop>
  4525.  
  4526. " unbind Left arrow key
  4527. "inoremap <left> <nop>
  4528. "vnoremap <left> <nop>
  4529.  
  4530. " unbind Right arrow key
  4531. "inoremap <right> <nop>
  4532. "vnoremap <right> <nop>
  4533.  
  4534.  
  4535. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  4536.  
  4537. """ Theme
  4538.  
  4539. let g:currentmode={
  4540. \ 'n' : 'N ',
  4541. \ 'no' : 'N·Operator Pending ',
  4542. \ 'v' : 'V ',
  4543. \ 'V' : 'V·Line ',
  4544. \ "\<C-V>" : 'V·Block ',
  4545. \ 's' : 'Select ',
  4546. \ 'S' : 'S·Line ',
  4547. \ "\<C-S>" : 'S·Block ',
  4548. \ 'i' : 'I ',
  4549. \ 'R' : 'R ',
  4550. \ 'Rv' : 'V·Replace ',
  4551. \ 'c' : 'Command ',
  4552. \ 'cv' : 'Vim Ex ',
  4553. \ 'ce' : 'Ex ',
  4554. \ 'r' : 'Prompt ',
  4555. \ 'rm' : 'More ',
  4556. \ 'r?' : 'Confirm ',
  4557. \ '!' : 'Shell ',
  4558. \ 't' : 'Terminal '
  4559. \}
  4560.  
  4561. " Automatically change the statusline color depending on mode
  4562. function! ChangeStatuslineColor()
  4563. if (mode() =~# '\v(n|no)')
  4564. exe 'hi! StatusLine ctermfg=008'
  4565. elseif (mode() =~# '\v(v|V)' || g:currentmode[mode()] ==# 'V·Block' || get(g:currentmode, mode(), '') ==# 't')
  4566. exe 'hi! StatusLine ctermfg=005'
  4567. elseif (mode() ==# 'i')
  4568. exe 'hi! StatusLine ctermfg=004'
  4569. else
  4570. exe 'hi! StatusLine ctermfg=006'
  4571. endif
  4572.  
  4573. return ''
  4574. endfunction
  4575.  
  4576. " Find out current buffer's size and output it.
  4577. function! FileSize()
  4578. let bytes = getfsize(expand('%:p'))
  4579. if (bytes >= 1024)
  4580. let kbytes = bytes / 1024
  4581. endif
  4582. if (exists('kbytes') && kbytes >= 1000)
  4583. let mbytes = kbytes / 1000
  4584. endif
  4585.  
  4586. if bytes <= 0
  4587. return '0'
  4588. endif
  4589.  
  4590. if (exists('mbytes'))
  4591. return mbytes . 'MB '
  4592. elseif (exists('kbytes'))
  4593. return kbytes . 'KB '
  4594. else
  4595. return bytes . 'B '
  4596. endif
  4597. endfunction
  4598.  
  4599. function! ReadOnly()
  4600. if &readonly || !&modifiable
  4601. return ''
  4602. else
  4603. return ''
  4604. endfunction
  4605.  
  4606.  
  4607. "" git status
  4608. function! GitBranch()
  4609. return system("git rev-parse --abbrev-ref HEAD 2>/dev/null | tr -d '\n'")
  4610. endfunction
  4611.  
  4612. function! StatuslineGit()
  4613. let l:branchname = GitBranch()
  4614. return strlen(l:branchname) > 0 ? ''.l:branchname.' ':''
  4615. endfunction
  4616.  
  4617.  
  4618. set laststatus=2
  4619. set statusline=
  4620. set statusline+=%{ChangeStatuslineColor()} " Changing the statusline color
  4621. set statusline+=%0*\ %{toupper(g:currentmode[mode()])} " Current mode
  4622. set statusline+=%8*\ [%n] " buffernr
  4623. set statusline+=%8*\ %{StatuslineGit()} " Git Branch name
  4624. set statusline+=%8*\ %<%F\ %{ReadOnly()}\ %m\ %w\ " File+path
  4625. set statusline+=%#warningmsg#
  4626. "set statusline+=%{SyntasticStatuslineFlag()} " Syntastic errors
  4627. set statusline+=%*
  4628. set statusline+=%9*\ %= " Space
  4629. set statusline+=%8*\ %y\ " FileType
  4630. set statusline+=%7*\ %{(&fenc!=''?&fenc:&enc)}\[%{&ff}]\
  4631. set statusline+=%8*\ %-3(%{FileSize()}%) " File size
  4632. set statusline+=%0*\ %3p%%\ \ %l:\ %3c\ " Rownumber/total (%)
  4633.  
  4634. hi User1 ctermfg=007
  4635. hi User2 ctermfg=008
  4636. hi User3 ctermfg=008
  4637. hi User4 ctermfg=008
  4638. hi User5 ctermfg=008
  4639. hi User7 ctermfg=008
  4640. hi User8 ctermfg=008
  4641. hi User9 ctermfg=007
  4642.  
  4643. " colors
  4644. set background=dark
  4645. if version > 580
  4646. hi clear
  4647. if exists("syntax_on")
  4648. syntax reset
  4649. endif
  4650. endif
  4651.  
  4652. set t_Co=256
  4653.  
  4654.  
  4655. hi Normal ctermfg=15 ctermbg=0 cterm=bold
  4656.  
  4657. hi IncSearch ctermfg=15 ctermbg=33 cterm=NONE
  4658.  
  4659. hi WildMenu ctermfg=NONE ctermbg=17 cterm=NONE
  4660.  
  4661. hi SignColumn ctermfg=234 ctermbg=60 cterm=NONE
  4662.  
  4663. hi SpecialComment ctermfg=33 ctermbg=NONE cterm=bold
  4664.  
  4665. hi Typedef ctermfg=80 ctermbg=NONE cterm=bold
  4666.  
  4667. hi Title ctermfg=15 ctermbg=NONE cterm=NONE
  4668.  
  4669. hi Folded ctermfg=234 ctermbg=109 cterm=NONE
  4670.  
  4671. hi PreCondit ctermfg=13 ctermbg=NONE cterm=NONE
  4672.  
  4673. hi Include ctermfg=13 ctermbg=NONE cterm=NONE
  4674.  
  4675. hi Float ctermfg=197 ctermbg=NONE cterm=NONE
  4676.  
  4677. hi StatusLineNC ctermfg=15 ctermbg=NONE cterm=bold
  4678.  
  4679. hi NonText ctermfg=237 ctermbg=NONE cterm=NONE
  4680.  
  4681. hi DiffText ctermfg=230 ctermbg=53 cterm=NONE
  4682.  
  4683. hi ErrorMsg ctermfg=15 ctermbg=52 cterm=NONE
  4684.  
  4685. hi Debug ctermfg=101 ctermbg=NONE cterm=NONE
  4686.  
  4687. hi PMenuSbar ctermfg=NONE ctermbg=60 cterm=NONE
  4688.  
  4689. hi Identifier ctermfg=80 ctermbg=NONE cterm=NONE
  4690.  
  4691. hi SpecialChar ctermfg=13 ctermbg=NONE cterm=bold
  4692.  
  4693. hi Conditional ctermfg=214 ctermbg=NONE cterm=bold
  4694.  
  4695. hi StorageClass ctermfg=80 ctermbg=NONE cterm=bold
  4696.  
  4697. hi Todo ctermfg=220 ctermbg=NONE cterm=NONE
  4698.  
  4699. hi Special ctermfg=13 ctermbg=NONE cterm=bold
  4700.  
  4701. hi LineNr ctermfg=58 ctermbg=NONE cterm=NONE
  4702.  
  4703. hi StatusLine ctermfg=15 ctermbg=NONE cterm=bold
  4704.  
  4705. hi Label ctermfg=214 ctermbg=NONE cterm=bold
  4706.  
  4707. hi PMenuSel ctermfg=15 ctermbg=0 cterm=NONE
  4708.  
  4709. hi Search ctermfg=15 ctermbg=33 cterm=NONE
  4710.  
  4711. hi Delimiter ctermfg=101 ctermbg=NONE cterm=NONE
  4712.  
  4713. hi Statement ctermfg=214 ctermbg=NONE cterm=bold
  4714.  
  4715. hi Comment ctermfg=33 ctermbg=NONE cterm=NONE
  4716.  
  4717. hi Character ctermfg=197 ctermbg=NONE cterm=NONE
  4718.  
  4719. hi TabLineSel ctermfg=15 ctermbg=33 cterm=bold
  4720.  
  4721. hi Number ctermfg=197 ctermbg=NONE cterm=NONE
  4722.  
  4723. hi Boolean ctermfg=197 ctermbg=NONE cterm=NONE
  4724.  
  4725. hi Operator ctermfg=214 ctermbg=NONE cterm=bold
  4726.  
  4727. hi CursorLine ctermfg=NONE ctermbg=233 cterm=NONE
  4728.  
  4729. hi TabLineFill ctermfg=234 ctermbg=66 cterm=bold
  4730.  
  4731. hi WarningMsg ctermfg=232 ctermbg=220 cterm=NONE
  4732.  
  4733. hi DiffDelete ctermfg=197 ctermbg=NONE cterm=NONE
  4734.  
  4735. hi CursorColumn ctermfg=NONE ctermbg=8 cterm=NONE
  4736.  
  4737. hi Define ctermfg=101 ctermbg=NONE cterm=NONE
  4738.  
  4739. hi Function ctermfg=80 ctermbg=NONE cterm=bold
  4740.  
  4741. hi FoldColumn ctermfg=234 ctermbg=109 cterm=NONE
  4742.  
  4743. hi PreProc ctermfg=13 ctermbg=NONE cterm=NONE
  4744.  
  4745. hi Visual ctermfg=58 ctermbg=0 cterm=NONE
  4746.  
  4747. hi Exception ctermfg=214 ctermbg=NONE cterm=bold
  4748.  
  4749. hi Keyword ctermfg=220 ctermbg=NONE cterm=bold
  4750.  
  4751. hi Type ctermfg=80 ctermbg=NONE cterm=bold
  4752.  
  4753. hi DiffChange ctermfg=230 ctermbg=24 cterm=NONE
  4754.  
  4755. hi Cursor ctermfg=NONE ctermbg=225 cterm=NONE
  4756.  
  4757. hi Error ctermfg=15 ctermbg=52 cterm=NONE
  4758.  
  4759. hi PMenu ctermfg=15 ctermbg=NONE cterm=NONE
  4760.  
  4761. hi SpecialKey ctermfg=220 ctermbg=NONE cterm=NONE
  4762.  
  4763. hi Constant ctermfg=197 ctermbg=NONE cterm=NONE
  4764.  
  4765. hi Tag ctermfg=214 ctermbg=NONE cterm=NONE
  4766.  
  4767. hi String ctermfg=76 ctermbg=NONE cterm=NONE
  4768.  
  4769. hi PMenuThumb ctermfg=NONE ctermbg=103 cterm=NONE
  4770.  
  4771. hi MatchParen ctermfg=15 ctermbg=161 cterm=bold
  4772.  
  4773. hi Repeat ctermfg=214 ctermbg=NONE cterm=bold
  4774.  
  4775. hi Directory ctermfg=39 ctermbg=NONE cterm=NONE
  4776.  
  4777. hi Structure ctermfg=214 ctermbg=NONE cterm=bold
  4778.  
  4779. hi Macro ctermfg=220 ctermbg=NONE cterm=NONE
  4780.  
  4781. hi DiffAdd ctermfg=NONE ctermbg=237 cterm=NONE
  4782.  
  4783. hi TabLine ctermfg=15 ctermbg=NONE cterm=bold
  4784.  
  4785. hi cursorim ctermfg=234 ctermbg=60 cterm=NONE
  4786.  
  4787. hi CursorLineNr ctermfg=154 ctermbg=0 cterm=NONE
  4788.  
  4789. hi VertSplit ctermfg=15 ctermbg=0 cterm=NONE
  4790.  
  4791. hi Folded ctermfg=15 ctermbg=0 cterm=NONE
  4792.  
  4793. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  4794.  
  4795. ============================================================================================================================
  4796.  
  4797. ## dunst
  4798.  
  4799. [global]
  4800. ##########################################
  4801. #
  4802. # Display
  4803. #
  4804. ##########################################
  4805. # Which monitor should the notifications be displayed on.
  4806. monitor = 0
  4807.  
  4808. # Display notification on focused monitor. Possible modes are:
  4809. # mouse: follow mouse pointer
  4810. # keyboard: follow window with keyboard focus
  4811. # none: don't follow anything
  4812. #
  4813. # "keyboard" needs a window manager that exports the
  4814. # _NET_ACTIVE_WINDOW property.
  4815. # This should be the case for almost all modern window managers.
  4816. #
  4817. # If this option is set to mouse or keyboard, the monitor option
  4818. # will be ignored.
  4819. follow = mouse
  4820.  
  4821. # The geometry of the window:
  4822. # [{width}]x{height}[+/-{x}+/-{y}]
  4823. # The geometry of the message window.
  4824. # The height is measured in number of notifications everything else
  4825. # in pixels. If the width is omitted but the height is given
  4826. # ("-geometry x2"), the message window expands over the whole screen
  4827. # (dmenu-like). If width is 0, the window expands to the longest
  4828. # message displayed. A positive x is measured from the left, a
  4829. # negative from the right side of the screen. Y is measured from
  4830. # the top and down respectively.
  4831. # The width can be negative. In this case the actual width is the
  4832. # screen width minus the width defined in within the geometry option.
  4833. geometry = "300x5-30+10"
  4834.  
  4835. # Show how many messages are currently hidden (because of geometry).
  4836. indicate_hidden = yes
  4837.  
  4838. # Shrink window if it's smaller than the width. Will be ignored if
  4839. # width is 0.
  4840. shrink = yes
  4841.  
  4842. # The transparency of the window. Range: [0; 100].
  4843. # This option will only work if a compositing window manager is
  4844. # present (e.g. xcompmgr, compiz, etc.).
  4845. transparency = 15
  4846.  
  4847. # The height of the entire notification. If the height is smaller
  4848. # than the font height and padding combined, it will be raised
  4849. # to the font height and padding.
  4850. notification_height = 0
  4851.  
  4852. # Draw a line of "separator_height" pixel height between two
  4853. # notifications.
  4854. # Set to 0 to disable.
  4855. separator_height = 2
  4856.  
  4857. # Padding between text and separator.
  4858. padding = 8
  4859.  
  4860. # Horizontal padding.
  4861. horizontal_padding = 8
  4862.  
  4863. # Defines width in pixels of frame around the notification window.
  4864. # Set to 0 to disable.
  4865. frame_width = 1
  4866.  
  4867. # Defines color of the frame around the notification window.
  4868. frame_color = "#FF1493"
  4869.  
  4870. # Define a color for the separator.
  4871. # possible values are:
  4872. # * auto: dunst tries to find a color fitting to the background;
  4873. # * foreground: use the same color as the foreground;
  4874. # * frame: use the same color as the frame;
  4875. # * anything else will be interpreted as a X color.
  4876. separator_color = frame
  4877.  
  4878. # Sort messages by urgency.
  4879. sort = yes
  4880.  
  4881. # Don't remove messages, if the user is idle (no mouse or keyboard input)
  4882. # for longer than idle_threshold seconds.
  4883. # Set to 0 to disable.
  4884. # Transient notifications ignore this setting.
  4885. idle_threshold = 20
  4886.  
  4887. ### Text ###
  4888.  
  4889. font = Terminus (TTF) 9
  4890.  
  4891. # The spacing between lines. If the height is smaller than the
  4892. # font height, it will get raised to the font height.
  4893. line_height = 1
  4894.  
  4895. # Possible values are:
  4896. # full: Allow a small subset of html markup in notifications:
  4897. # <b>bold</b>
  4898. # <i>italic</i>
  4899. # <s>strikethrough</s>
  4900. # <u>underline</u>
  4901. #
  4902. # For a complete reference see
  4903. # <http://developer.gnome.org/pango/stable/PangoMarkupFormat.html>.
  4904. #
  4905. # strip: This setting is provided for compatibility with some broken
  4906. # clients that send markup even though it's not enabled on the
  4907. # server. Dunst will try to strip the markup but the parsing is
  4908. # simplistic so using this option outside of matching rules for
  4909. # specific applications *IS GREATLY DISCOURAGED*.
  4910. #
  4911. # no: Disable markup parsing, incoming notifications will be treated as
  4912. # plain text. Dunst will not advertise that it has the body-markup
  4913. # capability if this is set as a global setting.
  4914. #
  4915. # It's important to note that markup inside the format option will be parsed
  4916. # regardless of what this is set to.
  4917. markup = full
  4918.  
  4919. # The format of the message. Possible variables are:
  4920. # %a appname
  4921. # %s summary
  4922. # %b body
  4923. # %i iconname (including its path)
  4924. # %I iconname (without its path)
  4925. # %p progress value if set ([ 0%] to [100%]) or nothing
  4926. # %n progress value if set without any extra characters
  4927. # %% Literal %
  4928. # Markup is allowed
  4929. format = "<b>%s</b>\n%b"
  4930.  
  4931. # Alignment of message text.
  4932. # Possible values are "left", "center" and "right".
  4933. alignment = left
  4934.  
  4935. # Show age of message if message is older than show_age_threshold
  4936. # seconds.
  4937. # Set to -1 to disable.
  4938. show_age_threshold = 60
  4939.  
  4940. # Split notifications into multiple lines if they don't fit into
  4941. # geometry.
  4942. word_wrap = yes
  4943.  
  4944. # When word_wrap is set to no, specify where to ellipsize long lines.
  4945. # Possible values are "start", "middle" and "end".
  4946. ellipsize = middle
  4947.  
  4948. # Ignore newlines '\n' in notifications.
  4949. ignore_newline = no
  4950.  
  4951. # Merge multiple notifications with the same content
  4952. stack_duplicates = true
  4953.  
  4954. # Hide the count of merged notifications with the same content
  4955. hide_duplicate_count = false
  4956.  
  4957. # Display indicators for URLs (U) and actions (A).
  4958. show_indicators = yes
  4959.  
  4960. ### Icons ###
  4961.  
  4962. # Align icons left/right/off
  4963. icon_position = off
  4964.  
  4965. # Scale larger icons down to this size, set to 0 to disable
  4966. max_icon_size = 32
  4967.  
  4968. # Paths to default icons.
  4969. icon_path = /usr/share/icons/gnome/16x16/status/:/usr/share/icons/gnome/16x16/devices/
  4970.  
  4971. ### History ###
  4972.  
  4973. # Should a notification popped up from history be sticky or timeout
  4974. # as if it would normally do.
  4975. sticky_history = yes
  4976.  
  4977. # Maximum amount of notifications kept in history
  4978. history_length = 20
  4979.  
  4980. ### Misc/Advanced ###
  4981.  
  4982. # dmenu path.
  4983. dmenu = /usr/bin/dmenu -p dunst:
  4984.  
  4985. # Browser for opening urls in context menu.
  4986. browser = /usr/bin/firefox -new-tab
  4987.  
  4988. # Always run rule-defined scripts, even if the notification is suppressed
  4989. always_run_script = true
  4990.  
  4991. # Define the title of the windows spawned by dunst
  4992. title = Dunst
  4993.  
  4994. # Define the class of the windows spawned by dunst
  4995. class = Dunst
  4996.  
  4997. # Print a notification on startup.
  4998. # This is mainly for error detection, since dbus (re-)starts dunst
  4999. # automatically after a crash.
  5000. startup_notification = false
  5001.  
  5002. ### Legacy
  5003.  
  5004. # Use the Xinerama extension instead of RandR for multi-monitor support.
  5005. # This setting is provided for compatibility with older nVidia drivers that
  5006. # do not support RandR and using it on systems that support RandR is highly
  5007. # discouraged.
  5008. #
  5009. # By enabling this setting dunst will not be able to detect when a monitor
  5010. # is connected or disconnected which might break follow mode if the screen
  5011. # layout changes.
  5012. force_xinerama = false
  5013.  
  5014. # Experimental features that may or may not work correctly. Do not expect them
  5015. # to have a consistent behaviour across releases.
  5016. [experimental]
  5017. # Calculate the dpi to use on a per-monitor basis.
  5018. # If this setting is enabled the Xft.dpi value will be ignored and instead
  5019. # dunst will attempt to calculate an appropriate dpi value for each monitor
  5020. # using the resolution and physical size. This might be useful in setups
  5021. # where there are multiple screens with very different dpi values.
  5022. per_monitor_dpi = false
  5023.  
  5024. [shortcuts]
  5025.  
  5026. # Shortcuts are specified as [modifier+][modifier+]...key
  5027. # Available modifiers are "ctrl", "mod1" (the alt-key), "mod2",
  5028. # "mod3" and "mod4" (windows-key).
  5029. # Xev might be helpful to find names for keys.
  5030.  
  5031. # Close notification.
  5032. close = ctrl+space
  5033.  
  5034. # Close all notifications.
  5035. close_all = ctrl+shift+space
  5036.  
  5037. # Redisplay last message(s).
  5038. # On the US keyboard layout "grave" is normally above TAB and left
  5039. # of "1". Make sure this key actually exists on your keyboard layout,
  5040. # e.g. check output of 'xmodmap -pke'
  5041. history = ctrl+grave
  5042.  
  5043. # Context menu.
  5044. context = ctrl+shift+period
  5045.  
  5046. [urgency_low]
  5047. # IMPORTANT: colors have to be defined in quotation marks.
  5048. # Otherwise the "#" and following would be interpreted as a comment.
  5049. background = "#000000"
  5050. foreground = "#67C8FF"
  5051. frame_color = "#67C8FF"
  5052. timeout = 5
  5053. # Icon for notifications with low urgency, uncomment to enable
  5054. #icon = /path/to/icon
  5055.  
  5056. [urgency_normal]
  5057. background = "#000000"
  5058. foreground = "#FF1493"
  5059. frame_color = "#FF1493"
  5060. timeout = 5
  5061. # Icon for notifications with normal urgency, uncomment to enable
  5062. #icon = /path/to/icon
  5063.  
  5064. [urgency_critical]
  5065. background = "#000000"
  5066. foreground = "#FF0000"
  5067. frame_color = "#FF0000"
  5068. timeout = 10
  5069. # Icon for notifications with critical urgency, uncomment to enable
  5070. #icon = /path/to/icon
  5071.  
  5072. # Every section that isn't one of the above is interpreted as a rules to
  5073. # override settings for certain messages.
  5074. # Messages can be matched by "appname", "summary", "body", "icon", "category",
  5075. # "msg_urgency" and you can override the "timeout", "urgency", "foreground",
  5076. # "background", "new_icon" and "format".
  5077. # Shell-like globbing will get expanded.
  5078. #
  5079. # SCRIPTING
  5080. # You can specify a script that gets run when the rule matches by
  5081. # setting the "script" option.
  5082. # The script will be called as follows:
  5083. # script appname summary body icon urgency
  5084. # where urgency can be "LOW", "NORMAL" or "CRITICAL".
  5085. #
  5086. # NOTE: if you don't want a notification to be displayed, set the format
  5087. # to "".
  5088. # NOTE: It might be helpful to run dunst -print in a terminal in order
  5089. # to find fitting options for rules.
  5090.  
  5091. #[espeak]
  5092. # summary = "*"
  5093. # script = dunst_espeak.sh
  5094.  
  5095. #[script-test]
  5096. # summary = "*script*"
  5097. # script = dunst_test.sh
  5098.  
  5099. #[ignore]
  5100. # # This notification will not be displayed
  5101. # summary = "foobar"
  5102. # format = ""
  5103.  
  5104. #[history-ignore]
  5105. # # This notification will not be saved in history
  5106. # summary = "foobar"
  5107. # history_ignore = yes
  5108.  
  5109. [signed_on]
  5110. appname = Pidgin
  5111. summary = "*signed on*"
  5112. urgency = low
  5113.  
  5114. [signed_off]
  5115. appname = Pidgin
  5116. summary = *signed off*
  5117. urgency = low
  5118.  
  5119. [says]
  5120. appname = Pidgin
  5121. summary = *says*
  5122. urgency = normal
  5123.  
  5124.  
  5125. # vim: ft=cfg
  5126.  
  5127. ============================================================================================================================
  5128.  
  5129. ## Firefox
  5130.  
  5131. ## edit preferences:
  5132.  
  5133. # Gerneral:
  5134.  
  5135. Check Spelling as You Type (off)
  5136.  
  5137. Automatically update search engines (off)
  5138.  
  5139. # Home:
  5140.  
  5141. Home Page: https://start.duckduckgo.com
  5142.  
  5143. Tops Sites (off)
  5144.  
  5145. Recommended by Pocket (off)
  5146.  
  5147. Highlights (off)
  5148.  
  5149. Snippets (off)
  5150.  
  5151. # Search:
  5152.  
  5153. Defaults Search Engine (duckduckgo)
  5154.  
  5155. Turn off all search suggestions
  5156.  
  5157. remove all search engines but duckduckgo
  5158.  
  5159. # Provacy & security:
  5160.  
  5161. Ask to save logins (off)
  5162.  
  5163. History (custom)
  5164.  
  5165. Always in private browser (on)
  5166.  
  5167. remember browsing and download history (off)
  5168.  
  5169. remember search and form history (off)
  5170.  
  5171. Clear hisotry when FF closes (yes), settings (all yes)
  5172.  
  5173. cookies:
  5174.  
  5175. keep until I close FF
  5176.  
  5177. third party (never)
  5178.  
  5179. addrs bar:
  5180.  
  5181. browsing hsitory (no)
  5182.  
  5183. Bookmarks (yes)
  5184.  
  5185. open tabs (yes)
  5186.  
  5187. Tracjing protection (always)
  5188.  
  5189. do not track (always)
  5190.  
  5191. prevent accessability (yes)
  5192.  
  5193. allow ff studies (no)
  5194.  
  5195.  
  5196. # install addons:
  5197.  
  5198. HTTPSeverywhere
  5199.  
  5200. privacy badger
  5201.  
  5202. cookie autodelete
  5203.  
  5204. noscript
  5205.  
  5206. ublock origin
  5207.  
  5208. umatrix
  5209.  
  5210. Decentraleyes
  5211.  
  5212. # delete all bookmarks
  5213.  
  5214. # about config tweaks:
  5215.  
  5216.  
  5217. privacy.firstparty.isolate = true
  5218.  
  5219.  
  5220. A result of the Tor Uplift effort, this preference isolates all browser identifier sources (e.g. cookies) to the first party domain, with the goal of preventing tracking across different domains. (Don't do this if you are using the Firefox Addon "Cookie AutoDelete" with Firefox v58 or below.)
  5221.  
  5222.  
  5223.  
  5224. privacy.resistFingerprinting = true
  5225.  
  5226.  
  5227. A result of the Tor Uplift effort, this preference makes Firefox more resistant to browser fingerprinting.
  5228.  
  5229.  
  5230. privacy.trackingprotection.enabled = true
  5231.  
  5232.  
  5233. This is Mozilla’s new built-in tracking protection. It uses Disconnect.me filter list, which is redundant if you are already using uBlock Origin 3rd party filters, therefore you should set it to false if you are using the add-on functionalities.
  5234.  
  5235.  
  5236. browser.cache.offline.enable = false
  5237.  
  5238.  
  5239. Disables offline cache.
  5240.  
  5241.  
  5242. browser.safebrowsing.malware.enabled = false
  5243.  
  5244.  
  5245. Disable Google Safe Browsing malware checks. Security risk, but privacy improvement.
  5246.  
  5247.  
  5248. browser.safebrowsing.phishing.enabled = false
  5249.  
  5250.  
  5251. Disable Google Safe Browsing and phishing protection. Security risk, but privacy improvement.
  5252.  
  5253.  
  5254. browser.send_pings = false
  5255.  
  5256.  
  5257. The attribute would be useful for letting websites track visitors’ clicks.
  5258.  
  5259.  
  5260. browser.sessionstore.max_tabs_undo = 0
  5261.  
  5262.  
  5263. Even with Firefox set to not remember history, your closed tabs are stored temporarily at Menu -> History -> Recently Closed Tabs.
  5264.  
  5265.  
  5266. browser.urlbar.speculativeConnect.enabled = false
  5267.  
  5268.  
  5269. Disable preloading of autocomplete URLs. Firefox preloads URLs that autocomplete when a user types into the address bar, which is a concern if URLs are suggested that the user does not want to connect to. Source
  5270.  
  5271.  
  5272. dom.battery.enabled = false
  5273.  
  5274.  
  5275. Website owners can track the battery status of your device. Source
  5276.  
  5277.  
  5278. dom.event.clipboardevents.enabled = false
  5279.  
  5280.  
  5281. Disable that websites can get notifications if you copy, paste, or cut something from a web page, and it lets them know which part of the page had been selected.
  5282.  
  5283.  
  5284. geo.enabled = false
  5285.  
  5286.  
  5287. Disables geolocation.
  5288.  
  5289.  
  5290. media.eme.enabled = false
  5291.  
  5292.  
  5293. Disables playback of DRM-controlled HTML5 content, which, if enabled, automatically downloads the Widevine Content Decryption Module provided by Google Inc. Details
  5294. DRM-controlled content that requires the Adobe Flash or Microsoft Silverlight NPAPI plugins will still play, if installed and enabled in Firefox.
  5295.  
  5296.  
  5297. media.gmp-widevinecdm.enabled = false
  5298.  
  5299.  
  5300. Disables the Widevine Content Decryption Module provided by Google Inc., used for the playback of DRM-controlled HTML5 content. Details
  5301.  
  5302.  
  5303. media.navigator.enabled = false
  5304.  
  5305.  
  5306. Websites can track the microphone and camera status of your device.
  5307.  
  5308.  
  5309. network.cookie.cookieBehavior = 1
  5310.  
  5311.  
  5312. Disable cookies
  5313. 0 = Accept all cookies by default
  5314. 1 = Only accept from the originating site (block third-party cookies)
  5315. 2 = Block all cookies by default
  5316.  
  5317.  
  5318. network.cookie.lifetimePolicy = 2
  5319.  
  5320.  
  5321. cookies are deleted at the end of the session
  5322. 0 = Accept cookies normally
  5323. 1 = Prompt for each cookie
  5324. 2 = Accept for current session only
  5325. 3 = Accept for N days
  5326.  
  5327.  
  5328. network.http.referer.trimmingPolicy = 2
  5329.  
  5330.  
  5331. Send only the scheme, host, and port in the Referer header
  5332. 0 = Send the full URL in the Referer header
  5333. 1 = Send the URL without its query string in the Referer header
  5334. 2 = Send only the scheme, host, and port in the Referer header
  5335.  
  5336.  
  5337. network.http.referer.XOriginPolicy = 2
  5338.  
  5339.  
  5340. Only send Referer header when the full hostnames match. (Note: if you notice significant breakage, you might try 1 combined with an XOriginTrimmingPolicy tweak below.) Source
  5341. 0 = Send Referer in all cases
  5342. 1 = Send Referer to same eTLD sites
  5343. 2 = Send Referer only when the full hostnames match
  5344.  
  5345.  
  5346. network.http.referer.XOriginTrimmingPolicy = 2
  5347.  
  5348.  
  5349. When sending Referer across origins, only send scheme, host, and port in the Referer header of cross-origin requests. Source
  5350. 0 = Send full url in Referer
  5351. 1 = Send url without query string in Referer
  5352. 2 = Only send scheme, host, and port in Referer
  5353.  
  5354.  
  5355. webgl.disabled = true
  5356.  
  5357.  
  5358. WebGL is a potential security risk. Source
  5359.  
  5360.  
  5361. browser.sessionstore.privacy_level = 2
  5362.  
  5363.  
  5364. This preference controls when to store extra information about a session: contents of forms, scrollbar positions, cookies, and POST data. Details
  5365. 0 = Store extra session data for any site. (Default starting with Firefox 4.)
  5366. 1 = Store extra session data for unencrypted (non-HTTPS) sites only. (Default before Firefox 4.)
  5367. 2 = Never store extra session data.
  5368.  
  5369.  
  5370. network.IDN_show_punycode = true
  5371.  
  5372.  
  5373. Not rendering IDNs as their Punycode equivalent leaves you open to phishing attacks that can be very difficult to notice. Source
  5374.  
  5375.  
  5376. extensions.blocklist.url = https://blocklists.settings.services.mozilla.com/v1/blocklist/3/%20/%20/
  5377.  
  5378.  
  5379. Limit the amount of identifiable information sent when requesting the Mozilla harmful extension blocklist.
  5380. Optionally, the blocklist can be disabled entirely by setting extensions.blocklist.enabled to false for increased privacy, but decreased security. Source
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement