summaryrefslogtreecommitdiffstats
path: root/2configs
diff options
context:
space:
mode:
Diffstat (limited to '2configs')
-rw-r--r--2configs/makefu/base.nix99
-rw-r--r--2configs/makefu/cgit-retiolum.nix69
-rw-r--r--2configs/tv/AO753.nix39
-rw-r--r--2configs/tv/CAC-CentOS-7-64bit.nix47
-rw-r--r--2configs/tv/CAC-Developer-1.nix6
-rw-r--r--2configs/tv/CAC-Developer-2.nix6
-rw-r--r--2configs/tv/base.nix188
-rw-r--r--2configs/tv/bash_completion.sh779
-rw-r--r--2configs/tv/charybdis.nix603
-rw-r--r--2configs/tv/consul-client.nix9
-rw-r--r--2configs/tv/consul-server.nix21
-rw-r--r--2configs/tv/cryptoroot.nix4
-rw-r--r--2configs/tv/exim-retiolum.nix126
-rw-r--r--2configs/tv/exim-smarthost.nix475
-rw-r--r--2configs/tv/git.nix90
-rw-r--r--2configs/tv/mail-client.nix14
-rw-r--r--2configs/tv/smartd.nix17
-rw-r--r--2configs/tv/synaptics.nix14
-rw-r--r--2configs/tv/urlwatch.nix51
-rw-r--r--2configs/tv/urxvt.nix24
-rw-r--r--2configs/tv/w110er.nix42
-rw-r--r--2configs/tv/xserver.nix41
22 files changed, 0 insertions, 2764 deletions
diff --git a/2configs/makefu/base.nix b/2configs/makefu/base.nix
deleted file mode 100644
index b052b13e4..000000000
--- a/2configs/makefu/base.nix
+++ /dev/null
@@ -1,99 +0,0 @@
-{ config, lib, pkgs, ... }:
-
-with lib;
-{
- imports = [ ];
- krebs.enable = true;
- krebs.search-domain = "retiolum";
-
- networking.hostName = config.krebs.build.host.name;
- users.extraUsers = {
- root = {
- openssh.authorizedKeys.keys = [ config.krebs.users.makefu.pubkey ];
- };
- makefu = {
- uid = 9001;
- group = "users";
- home = "/home/makefu";
- createHome = true;
- useDefaultShell = true;
- extraGroups = [
- "wheel"
- ];
- openssh.authorizedKeys.keys = [ config.krebs.users.makefu.pubkey ];
- };
- };
-
- services.openssh.enable = true;
- nix.useChroot = true;
-
- users.mutableUsers = true;
-
- boot.tmpOnTmpfs = true;
- systemd.tmpfiles.rules = [
- "d /tmp 1777 root root - -"
- ];
-
- environment.extraInit = ''
- EDITOR=vim
- '';
-
- environment.systemPackages = with pkgs; [
- git
- vim
- gnumake
- rxvt_unicode.terminfo
- ];
-
- programs.bash = {
- enableCompletion = true;
- interactiveShellInit = ''
- HISTCONTROL='erasedups:ignorespace'
- HISTSIZE=900001
- HISTFILESIZE=$HISTSIZE
-
- shopt -s checkhash
- shopt -s histappend histreedit histverify
- shopt -s no_empty_cmd_completion
- complete -d cd
- '';
-
- promptInit = ''
- case $UID in
- 0) PS1='\[\e[1;31m\]\w\[\e[0m\] ' ;;
- 9001) PS1='\[\e[1;32m\]\w\[\e[0m\] ' ;;
- *) PS1='\[\e[1;35m\]\u \[\e[1;32m\]\w\[\e[0m\] ' ;;
- esac
- if test -n "$SSH_CLIENT"; then
- PS1='\[\033[35m\]\h'" $PS1"
- fi
- '';
- };
-
- environment.shellAliases = {
- lsl = "ls -lAtr";
- };
-
- nixpkgs.config.packageOverrides = pkgs: {
- nano = pkgs.runCommand "empty" {} "mkdir -p $out";
- };
-
- services.cron.enable = false;
- services.nscd.enable = false;
-
- security.setuidPrograms = [ "sendmail" ];
- services.journald.extraConfig = ''
- SystemMaxUse=1G
- RuntimeMaxUse=128M
- '';
- # Enable IPv6 Privacy Extensions
- boot.kernel.sysctl = {
- "net.ipv6.conf.all.use_tempaddr" = 2;
- "net.ipv6.conf.default.use_tempaddr" = 2;
- };
-
- i18n = {
- consoleKeyMap = "us";
- defaultLocale = "en_US.UTF-8";
- };
-}
diff --git a/2configs/makefu/cgit-retiolum.nix b/2configs/makefu/cgit-retiolum.nix
deleted file mode 100644
index d0351a9af..000000000
--- a/2configs/makefu/cgit-retiolum.nix
+++ /dev/null
@@ -1,69 +0,0 @@
-{ config, lib, pkgs, ... }:
-# TODO: remove tv lib :)
-with import ../../4lib/tv { inherit lib pkgs; };
-let
-
- repos = priv-repos // krebs-repos ;
- rules = concatMap krebs-rules (attrValues krebs-repos) ++ concatMap priv-rules (attrValues priv-repos);
-
- krebs-repos = mapAttrs make-krebs-repo {
- stockholm = {
- desc = "take all the computers hostage, they'll love you!";
- };
- };
-
- priv-repos = mapAttrs make-priv-repo {
- autosync = { };
- };
-
-
- # TODO move users to separate module
- make-priv-repo = name: { desc ? null, ... }: {
- inherit name desc;
- public = false;
- };
-
- make-krebs-repo = with git; name: { desc ? null, ... }: {
- inherit name desc;
- public = true;
- hooks = {
- post-receive = git.irc-announce {
- nick = config.networking.hostName;
- channel = "#retiolum";
- server = "cd.retiolum";
- };
- };
- };
-
- set-owners = with git; repo: user:
- singleton {
- inherit user;
- repo = [ repo ];
- perm = push "refs/*" [ non-fast-forward create delete merge ];
- };
-
- set-ro-access = with git; repo: user:
- optional repo.public {
- inherit user;
- repo = [ repo ];
- perm = fetch;
- };
-
- # TODO: get the list of all krebsministers
- krebsminister = with config.krebs.users; [ lass tv uriel ];
-
- priv-rules = with config.krebs.users; repo:
- set-owners repo [ makefu ];
-
- krebs-rules = with config.krebs.users; repo:
- set-owners repo [ makefu ] ++ set-ro-access repo krebsminister ;
-
-in {
- imports = [ ../../3modules/krebs/git.nix ];
- krebs.git = {
- enable = true;
- root-title = "public repositories ";
- root-desc = "keep on krebsing";
- inherit repos rules;
- };
-}
diff --git a/2configs/tv/AO753.nix b/2configs/tv/AO753.nix
deleted file mode 100644
index 70eae1786..000000000
--- a/2configs/tv/AO753.nix
+++ /dev/null
@@ -1,39 +0,0 @@
-{ config, pkgs, ... }:
-
-{
- imports = [
- ../../2configs/tv/smartd.nix
- ];
-
- boot.loader.grub = {
- device = "/dev/sda";
- splashImage = null;
- };
-
- boot.initrd.availableKernelModules = [
- "ahci"
- ];
-
- boot.kernelModules = [
- "kvm-intel"
- "wl"
- ];
-
- boot.extraModulePackages = [
- config.boot.kernelPackages.broadcom_sta
- ];
-
- networking.wireless.enable = true;
-
- services.logind.extraConfig = ''
- HandleHibernateKey=ignore
- HandleLidSwitch=ignore
- HandlePowerKey=ignore
- HandleSuspendKey=ignore
- '';
-
- nixpkgs.config = {
- allowUnfree = false;
- allowUnfreePredicate = (x: pkgs.lib.hasPrefix "broadcom-sta-" x.name);
- };
-}
diff --git a/2configs/tv/CAC-CentOS-7-64bit.nix b/2configs/tv/CAC-CentOS-7-64bit.nix
deleted file mode 100644
index 95c6e815c..000000000
--- a/2configs/tv/CAC-CentOS-7-64bit.nix
+++ /dev/null
@@ -1,47 +0,0 @@
-_:
-
-{
- boot.loader.grub = {
- device = "/dev/sda";
- splashImage = null;
- };
-
- boot.initrd.availableKernelModules = [
- "ata_piix"
- "vmw_pvscsi"
- ];
-
- fileSystems."/" = {
- device = "/dev/centos/root";
- fsType = "xfs";
- };
-
- fileSystems."/boot" = {
- device = "/dev/sda1";
- fsType = "xfs";
- };
-
- swapDevices = [
- { device = "/dev/centos/swap"; }
- ];
-
- users.extraGroups = {
- # ● systemd-tmpfiles-setup.service - Create Volatile Files and Directories
- # Loaded: loaded (/nix/store/2l33gg7nmncqkpysq9f5fxyhlw6ncm2j-systemd-217/example/systemd/system/systemd-tmpfiles-setup.service)
- # Active: failed (Result: exit-code) since Mon 2015-03-16 10:29:18 UTC; 4s ago
- # Docs: man:tmpfiles.d(5)
- # man:systemd-tmpfiles(8)
- # Process: 19272 ExecStart=/nix/store/2l33gg7nmncqkpysq9f5fxyhlw6ncm2j-systemd-217/bin/systemd-tmpfiles --create --remove --boot --exclude-prefix=/dev (code=exited, status=1/FAILURE)
- # Main PID: 19272 (code=exited, status=1/FAILURE)
- #
- # Mar 16 10:29:17 cd systemd-tmpfiles[19272]: [/usr/lib/tmpfiles.d/legacy.conf:26] Unknown group 'lock'.
- # Mar 16 10:29:18 cd systemd-tmpfiles[19272]: Two or more conflicting lines for /var/log/journal configured, ignoring.
- # Mar 16 10:29:18 cd systemd-tmpfiles[19272]: Two or more conflicting lines for /var/log/journal/7b35116927d74ea58785e00b47ac0f0d configured, ignoring.
- # Mar 16 10:29:18 cd systemd[1]: systemd-tmpfiles-setup.service: main process exited, code=exited, status=1/FAILURE
- # Mar 16 10:29:18 cd systemd[1]: Failed to start Create Volatile Files and Directories.
- # Mar 16 10:29:18 cd systemd[1]: Unit systemd-tmpfiles-setup.service entered failed state.
- # Mar 16 10:29:18 cd systemd[1]: systemd-tmpfiles-setup.service failed.
- # warning: error(s) occured while switching to the new configuration
- lock.gid = 10001;
- };
-}
diff --git a/2configs/tv/CAC-Developer-1.nix b/2configs/tv/CAC-Developer-1.nix
deleted file mode 100644
index 37bc32afb..000000000
--- a/2configs/tv/CAC-Developer-1.nix
+++ /dev/null
@@ -1,6 +0,0 @@
-_:
-
-{
- nix.maxJobs = 1;
- sound.enable = false;
-}
diff --git a/2configs/tv/CAC-Developer-2.nix b/2configs/tv/CAC-Developer-2.nix
deleted file mode 100644
index fedb808df..000000000
--- a/2configs/tv/CAC-Developer-2.nix
+++ /dev/null
@@ -1,6 +0,0 @@
-_:
-
-{
- nix.maxJobs = 2;
- sound.enable = false;
-}
diff --git a/2configs/tv/base.nix b/2configs/tv/base.nix
deleted file mode 100644
index 06f83ea9e..000000000
--- a/2configs/tv/base.nix
+++ /dev/null
@@ -1,188 +0,0 @@
-{ config, lib, pkgs, ... }:
-
-with builtins;
-with lib;
-
-let
- # "7.4.335" -> "74"
- majmin = x: concatStrings (take 2 (splitString "." x));
-in
-
-{
- krebs.enable = true;
- krebs.search-domain = "retiolum";
-
- networking.hostName = config.krebs.build.host.name;
-
- imports = [
- {
- users.extraUsers =
- mapAttrs (_: h: { hashedPassword = h; })
- (import /root/src/secrets/hashedPasswords.nix);
- }
- {
- users.defaultUserShell = "/run/current-system/sw/bin/bash";
- users.mutableUsers = false;
- }
- {
- users.extraUsers = {
- root = {
- openssh.authorizedKeys.keys = [
- config.krebs.users.tv.pubkey
- ];
- };
- tv = {
- uid = 1337;
- group = "users";
- home = "/home/tv";
- createHome = true;
- useDefaultShell = true;
- extraGroups = [
- "audio"
- "video"
- "wheel"
- ];
- openssh.authorizedKeys.keys = [
- config.krebs.users.tv.pubkey
- ];
- };
- };
- }
- {
- security.sudo.extraConfig = ''
- Defaults mailto="${config.krebs.users.tv.mail}"
- '';
- time.timeZone = "Europe/Berlin";
- }
- {
- # TODO check if both are required:
- nix.chrootDirs = [ "/etc/protocols" pkgs.iana_etc.outPath ];
-
- nix.trustedBinaryCaches = [
- "https://cache.nixos.org"
- "http://cache.nixos.org"
- "http://hydra.nixos.org"
- ];
-
- nix.useChroot = true;
- }
- {
- # oldvim
- environment.systemPackages = with pkgs; [
- vim
- ];
-
- environment.etc."vim/vimrc".text = ''
- set nocp
- '';
-
- environment.etc."vim/vim${majmin pkgs.vim.version}".source =
- "${pkgs.vim}/share/vim/vim${majmin pkgs.vim.version}";
-
- # multiple-definition-problem when defining environment.variables.EDITOR
- environment.extraInit = ''
- EDITOR=vim
- '';
-
- environment.variables.VIM = "/etc/vim";
- }
- {
- environment.systemPackages = with pkgs; [
- rxvt_unicode.terminfo
- ];
-
- environment.shellAliases = {
- # alias cal='cal -m3'
- gp = "${pkgs.pari}/bin/gp -q";
- df = "df -h";
- du = "du -h";
- # alias grep='grep --color=auto'
-
- # TODO alias cannot contain #\'
- # "ps?" = "ps ax | head -n 1;ps ax | fgrep -v ' grep --color=auto ' | grep";
-
- # alias la='ls -lA'
- lAtr = "ls -lAtr";
- # alias ll='ls -l'
- ls = "ls -h --color=auto --group-directories-first";
- # alias vim='vim -p'
- # alias vi='vim'
- # alias view='vim -R'
- dmesg = "dmesg -L --reltime";
- };
-
- programs.bash = {
- interactiveShellInit = ''
- HISTCONTROL='erasedups:ignorespace'
- HISTSIZE=65536
- HISTFILESIZE=$HISTSIZE
-
- shopt -s checkhash
- shopt -s histappend histreedit histverify
- shopt -s no_empty_cmd_completion
- complete -d cd
-
- ${readFile ./bash_completion.sh}
-
- # TODO source bridge
- '';
- promptInit = ''
- case $UID in
- 0)
- PS1='\[\e[1;31m\]\w\[\e[0m\] '
- ;;
- 1337)
- PS1='\[\e[1;32m\]\w\[\e[0m\] '
- ;;
- *)
- PS1='\[\e[1;35m\]\u \[\e[1;32m\]\w\[\e[0m\] '
- ;;
- esac
- if test -n "$SSH_CLIENT"; then
- PS1='\[\e[35m\]\h'" $PS1"
- fi
- if test -n "$SSH_AGENT_PID"; then
- PS1="ssh-agent[$SSH_AGENT_PID] $PS1"
- fi
- '';
- };
-
- programs.ssh.startAgent = false;
- }
-
- {
- nixpkgs.config.packageOverrides = pkgs:
- {
- nano = pkgs.runCommand "empty" {} "mkdir -p $out";
- };
-
- services.cron.enable = false;
- services.nscd.enable = false;
- services.ntp.enable = false;
- }
-
- {
- boot.kernel.sysctl = {
- # Enable IPv6 Privacy Extensions
- "net.ipv6.conf.all.use_tempaddr" = 2;
- "net.ipv6.conf.default.use_tempaddr" = 2;
- };
- }
-
- {
- services.openssh = {
- enable = true;
- hostKeys = [
- { type = "ed25519"; path = "/etc/ssh/ssh_host_ed25519_key"; }
- ];
- };
- }
-
- {
- # TODO: exim
- security.setuidPrograms = [
- "sendmail" # for sudo
- ];
- }
- ];
-}
diff --git a/2configs/tv/bash_completion.sh b/2configs/tv/bash_completion.sh
deleted file mode 100644
index 537484fb9..000000000
--- a/2configs/tv/bash_completion.sh
+++ /dev/null
@@ -1,779 +0,0 @@
-
-# Expand variable starting with tilde (~)
-# We want to expand ~foo/... to /home/foo/... to avoid problems when
-# word-to-complete starting with a tilde is fed to commands and ending up
-# quoted instead of expanded.
-# Only the first portion of the variable from the tilde up to the first slash
-# (~../) is expanded. The remainder of the variable, containing for example
-# a dollar sign variable ($) or asterisk (*) is not expanded.
-# Example usage:
-#
-# $ v="~"; __expand_tilde_by_ref v; echo "$v"
-#
-# Example output:
-#
-# v output
-# -------- ----------------
-# ~ /home/user
-# ~foo/bar /home/foo/bar
-# ~foo/$HOME /home/foo/$HOME
-# ~foo/a b /home/foo/a b
-# ~foo/* /home/foo/*
-#
-# @param $1 Name of variable (not the value of the variable) to expand
-__expand_tilde_by_ref()
-{
- # Does $1 start with tilde (~)?
- if [[ ${!1} == \~* ]]; then
- # Does $1 contain slash (/)?
- if [[ ${!1} == */* ]]; then
- # Yes, $1 contains slash;
- # 1: Remove * including and after first slash (/), i.e. "~a/b"
- # becomes "~a". Double quotes allow eval.
- # 2: Remove * before the first slash (/), i.e. "~a/b"
- # becomes "b". Single quotes prevent eval.
- # +-----1----+ +---2----+
- eval $1="${!1/%\/*}"/'${!1#*/}'
- else
- # No, $1 doesn't contain slash
- eval $1="${!1}"
- fi
- fi
-} # __expand_tilde_by_ref()
-
-
-# Get the word to complete.
-# This is nicer than ${COMP_WORDS[$COMP_CWORD]}, since it handles cases
-# where the user is completing in the middle of a word.
-# (For example, if the line is "ls foobar",
-# and the cursor is here --------> ^
-# @param $1 string Characters out of $COMP_WORDBREAKS which should NOT be
-# considered word breaks. This is useful for things like scp where
-# we want to return host:path and not only path, so we would pass the
-# colon (:) as $1 in this case.
-# @param $2 integer Index number of word to return, negatively offset to the
-# current word (default is 0, previous is 1), respecting the exclusions
-# given at $1. For example, `_get_cword "=:" 1' returns the word left of
-# the current word, respecting the exclusions "=:".
-# @deprecated Use `_get_comp_words_by_ref cur' instead
-# @see _get_comp_words_by_ref()
-_get_cword()
-{
- local LC_CTYPE=C
- local cword words
- __reassemble_comp_words_by_ref "$1" words cword
-
- # return previous word offset by $2
- if [[ ${2//[^0-9]/} ]]; then
- printf "%s" "${words[cword-$2]}"
- elif [[ "${#words[cword]}" -eq 0 || "$COMP_POINT" == "${#COMP_LINE}" ]]; then
- printf "%s" "${words[cword]}"
- else
- local i
- local cur="$COMP_LINE"
- local index="$COMP_POINT"
- for (( i = 0; i <= cword; ++i )); do
- while [[
- # Current word fits in $cur?
- "${#cur}" -ge ${#words[i]} &&
- # $cur doesn't match cword?
- "${cur:0:${#words[i]}}" != "${words[i]}"
- ]]; do
- # Strip first character
- cur="${cur:1}"
- # Decrease cursor position
- ((index--))
- done
-
- # Does found word matches cword?
- if [[ "$i" -lt "$cword" ]]; then
- # No, cword lies further;
- local old_size="${#cur}"
- cur="${cur#${words[i]}}"
- local new_size="${#cur}"
- index=$(( index - old_size + new_size ))
- fi
- done
-
- if [[ "${words[cword]:0:${#cur}}" != "$cur" ]]; then
- # We messed up! At least return the whole word so things
- # keep working
- printf "%s" "${words[cword]}"
- else
- printf "%s" "${cur:0:$index}"
- fi
- fi
-} # _get_cword()
-
-
-# Get word previous to the current word.
-# This is a good alternative to `prev=${COMP_WORDS[COMP_CWORD-1]}' because bash4
-# will properly return the previous word with respect to any given exclusions to
-# COMP_WORDBREAKS.
-# @deprecated Use `_get_comp_words_by_ref cur prev' instead
-# @see _get_comp_words_by_ref()
-#
-_get_pword()
-{
- if [[ $COMP_CWORD -ge 1 ]]; then
- _get_cword "${@:-}" 1
- fi
-}
-
-
-
-# Complete variables.
-# @return True (0) if variables were completed,
-# False (> 0) if not.
-_variables()
-{
- if [[ $cur =~ ^(\$\{?)([A-Za-z0-9_]*)$ ]]; then
- [[ $cur == *{* ]] && local suffix=} || local suffix=
- COMPREPLY+=( $( compgen -P ${BASH_REMATCH[1]} -S "$suffix" -v -- \
- "${BASH_REMATCH[2]}" ) )
- return 0
- fi
- return 1
-}
-
-# Assign variable one scope above the caller
-# Usage: local "$1" && _upvar $1 "value(s)"
-# Param: $1 Variable name to assign value to
-# Param: $* Value(s) to assign. If multiple values, an array is
-# assigned, otherwise a single value is assigned.
-# NOTE: For assigning multiple variables, use '_upvars'. Do NOT
-# use multiple '_upvar' calls, since one '_upvar' call might
-# reassign a variable to be used by another '_upvar' call.
-# See: http://fvue.nl/wiki/Bash:_Passing_variables_by_reference
-_upvar()
-{
- if unset -v "$1"; then # Unset & validate varname
- if (( $# == 2 )); then
- eval $1=\"\$2\" # Return single value
- else
- eval $1=\(\"\${@:2}\"\) # Return array
- fi
- fi
-}
-
-# Assign variables one scope above the caller
-# Usage: local varname [varname ...] &&
-# _upvars [-v varname value] | [-aN varname [value ...]] ...
-# Available OPTIONS:
-# -aN Assign next N values to varname as array
-# -v Assign single value to varname
-# Return: 1 if error occurs
-# See: http://fvue.nl/wiki/Bash:_Passing_variables_by_reference
-_upvars()
-{
- if ! (( $# )); then
- echo "${FUNCNAME[0]}: usage: ${FUNCNAME[0]} [-v varname"\
- "value] | [-aN varname [value ...]] ..." 1>&2
- return 2
- fi
- while (( $# )); do
- case $1 in
- -a*)
- # Error checking
- [[ ${1#-a} ]] || { echo "bash: ${FUNCNAME[0]}: \`$1': missing"\
- "number specifier" 1>&2; return 1; }
- printf %d "${1#-a}" &> /dev/null || { echo "bash:"\
- "${FUNCNAME[0]}: \`$1': invalid number specifier" 1>&2
- return 1; }
- # Assign array of -aN elements
- [[ "$2" ]] && unset -v "$2" && eval $2=\(\"\${@:3:${1#-a}}\"\) &&
- shift $((${1#-a} + 2)) || { echo "bash: ${FUNCNAME[0]}:"\
- "\`$1${2+ }$2': missing argument(s)" 1>&2; return 1; }
- ;;
- -v)
- # Assign single value
- [[ "$2" ]] && unset -v "$2" && eval $2=\"\$3\" &&
- shift 3 || { echo "bash: ${FUNCNAME[0]}: $1: missing"\
- "argument(s)" 1>&2; return 1; }
- ;;
- *)
- echo "bash: ${FUNCNAME[0]}: $1: invalid option" 1>&2
- return 1 ;;
- esac
- done
-}
-
-# @param $1 exclude Characters out of $COMP_WORDBREAKS which should NOT be
-# considered word breaks. This is useful for things like scp where
-# we want to return host:path and not only path, so we would pass the
-# colon (:) as $1 in this case.
-# @param $2 words Name of variable to return words to
-# @param $3 cword Name of variable to return cword to
-# @param $4 cur Name of variable to return current word to complete to
-# @see __reassemble_comp_words_by_ref()
-__get_cword_at_cursor_by_ref()
-{
- local cword words=()
- __reassemble_comp_words_by_ref "$1" words cword
-
- local i cur index=$COMP_POINT lead=${COMP_LINE:0:$COMP_POINT}
- # Cursor not at position 0 and not leaded by just space(s)?
- if [[ $index -gt 0 && ( $lead && ${lead//[[:space:]]} ) ]]; then
- cur=$COMP_LINE
- for (( i = 0; i <= cword; ++i )); do
- while [[
- # Current word fits in $cur?
- ${#cur} -ge ${#words[i]} &&
- # $cur doesn't match cword?
- "${cur:0:${#words[i]}}" != "${words[i]}"
- ]]; do
- # Strip first character
- cur="${cur:1}"
- # Decrease cursor position
- ((index--))
- done
-
- # Does found word match cword?
- if [[ $i -lt $cword ]]; then
- # No, cword lies further;
- local old_size=${#cur}
- cur="${cur#"${words[i]}"}"
- local new_size=${#cur}
- index=$(( index - old_size + new_size ))
- fi
- done
- # Clear $cur if just space(s)
- [[ $cur && ! ${cur//[[:space:]]} ]] && cur=
- # Zero $index if negative
- [[ $index -lt 0 ]] && index=0
- fi
-
- local "$2" "$3" "$4" && _upvars -a${#words[@]} $2 "${words[@]}" \
- -v $3 "$cword" -v $4 "${cur:0:$index}"
-}
-
-# Reassemble command line words, excluding specified characters from the
-# list of word completion separators (COMP_WORDBREAKS).
-# @param $1 chars Characters out of $COMP_WORDBREAKS which should
-# NOT be considered word breaks. This is useful for things like scp where
-# we want to return host:path and not only path, so we would pass the
-# colon (:) as $1 here.
-# @param $2 words Name of variable to return words to
-# @param $3 cword Name of variable to return cword to
-#
-__reassemble_comp_words_by_ref()
-{
- local exclude i j line ref
- # Exclude word separator characters?
- if [[ $1 ]]; then
- # Yes, exclude word separator characters;
- # Exclude only those characters, which were really included
- exclude="${1//[^$COMP_WORDBREAKS]}"
- fi
-
- # Default to cword unchanged
- eval $3=$COMP_CWORD
- # Are characters excluded which were former included?
- if [[ $exclude ]]; then
- # Yes, list of word completion separators has shrunk;
- line=$COMP_LINE
- # Re-assemble words to complete
- for (( i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do
- # Is current word not word 0 (the command itself) and is word not
- # empty and is word made up of just word separator characters to
- # be excluded and is current word not preceded by whitespace in
- # original line?
- while [[ $i -gt 0 && ${COMP_WORDS[$i]} == +([$exclude]) ]]; do
- # Is word separator not preceded by whitespace in original line
- # and are we not going to append to word 0 (the command
- # itself), then append to current word.
- [[ $line != [$' \t']* ]] && (( j >= 2 )) && ((j--))
- # Append word separator to current or new word
- ref="$2[$j]"
- eval $2[$j]=\${!ref}\${COMP_WORDS[i]}
- # Indicate new cword
- [[ $i == $COMP_CWORD ]] && eval $3=$j
- # Remove optional whitespace + word separator from line copy
- line=${line#*"${COMP_WORDS[$i]}"}
- # Start new word if word separator in original line is
- # followed by whitespace.
- [[ $line == [$' \t']* ]] && ((j++))
- # Indicate next word if available, else end *both* while and
- # for loop
- (( $i < ${#COMP_WORDS[@]} - 1)) && ((i++)) || break 2
- done
- # Append word to current word
- ref="$2[$j]"
- eval $2[$j]=\${!ref}\${COMP_WORDS[i]}
- # Remove optional whitespace + word from line copy
- line=${line#*"${COMP_WORDS[i]}"}
- # Indicate new cword
- [[ $i == $COMP_CWORD ]] && eval $3=$j
- done
- [[ $i == $COMP_CWORD ]] && eval $3=$j
- else
- # No, list of word completions separators hasn't changed;
- eval $2=\( \"\${COMP_WORDS[@]}\" \)
- fi
-} # __reassemble_comp_words_by_ref()
-
-
-# If the word-to-complete contains a colon (:), left-trim COMPREPLY items with
-# word-to-complete.
-# With a colon in COMP_WORDBREAKS, words containing
-# colons are always completed as entire words if the word to complete contains
-# a colon. This function fixes this, by removing the colon-containing-prefix
-# from COMPREPLY items.
-# The preferred solution is to remove the colon (:) from COMP_WORDBREAKS in
-# your .bashrc:
-#
-# # Remove colon (:) from list of word completion separators
-# COMP_WORDBREAKS=${COMP_WORDBREAKS//:}
-#
-# See also: Bash FAQ - E13) Why does filename completion misbehave if a colon
-# appears in the filename? - http://tiswww.case.edu/php/chet/bash/FAQ
-# @param $1 current word to complete (cur)
-# @modifies global array $COMPREPLY
-#
-__ltrim_colon_completions()
-{
- if [[ "$1" == *:* && "$COMP_WORDBREAKS" == *:* ]]; then
- # Remove colon-word prefix from COMPREPLY items
- local colon_word=${1%"${1##*:}"}
- local i=${#COMPREPLY[*]}
- while [[ $((--i)) -ge 0 ]]; do
- COMPREPLY[$i]=${COMPREPLY[$i]#"$colon_word"}
- done
- fi
-} # __ltrim_colon_completions()
-
-
-# NOTE: Using this function as a helper function is deprecated. Use
-# `_known_hosts_real' instead.
-_known_hosts()
-{
- local cur prev words cword
- _init_completion -n : || return
-
- # NOTE: Using `_known_hosts' as a helper function and passing options
- # to `_known_hosts' is deprecated: Use `_known_hosts_real' instead.
- local options
- [[ "$1" == -a || "$2" == -a ]] && options=-a
- [[ "$1" == -c || "$2" == -c ]] && options+=" -c"
- _known_hosts_real $options -- "$cur"
-} # _known_hosts()
-
-
-# Helper function for completing _known_hosts.
-# This function performs host completion based on ssh's config and known_hosts
-# files, as well as hostnames reported by avahi-browse if
-# COMP_KNOWN_HOSTS_WITH_AVAHI is set to a non-empty value. A