Skip to main content
deleted 2 characters in body
Source Link
frabjous
  • 8.8k
  • 1
  • 35
  • 34

# for regular use, keep this alias
alias v='nvim'

# replace sudo with this functiom
sudo() {
    # check if next argument is 'v'
    if [[ "$1" == "v" ]] ; then
        # remove 'v' from the argument list
        shift

        # call sudo -E nvim on remaining arguments
        command sudo -E nvim "$@"

        # exit the function with the return value of the
        # sudo nvim -E command
        return $?
    fi

    # now check if first argument is a different alias; if so,
    # $expansion will be the alias definition if one exists,
    # or else it will be the empty string
    local expansion="${BASH_ALIASES[$1]}"
    if [[ -n "$expansion" ]] ; then
        # remove the alias from the argument list
        shift

        #if the expansion has variables in it,
        #we need to expand those variables, not
        #just the $expansion variable itself,
        #so we use eval
        eval "command sudo $expansion \"\$@\""

        # exit the function with its return value
        return "$$?"
    fi
    # if we got here, what follows sudo is a
    # normal command, so we execute sudo with the
    # rest of the arguments as is
    command sudo "$@"
}

# for regular use, keep this alias
alias v='nvim'

# replace sudo with this functiom
sudo() {
    # check if next argument is 'v'
    if [[ "$1" == "v" ]] ; then
        # remove 'v' from the argument list
        shift

        # call sudo -E nvim on remaining arguments
        command sudo -E nvim "$@"

        # exit the function with the return value of the
        # sudo nvim -E command
        return $?
    fi

    # now check if first argument is a different alias; if so,
    # $expansion will be the alias definition if one exists,
    # or else it will be the empty string
    local expansion="${BASH_ALIASES[$1]}"
    if [[ -n "$expansion" ]] ; then
        # remove the alias from the argument list
        shift

        #if the expansion has variables in it,
        #we need to expand those variables, not
        #just the $expansion variable itself,
        #so we use eval
        eval "command sudo $expansion \"\$@\""

        # exit the function with its return value
        return "$?"
    fi
    # if we got here, what follows sudo is a
    # normal command, so we execute sudo with the
    # rest of the arguments as is
    command sudo "$@"
}

# for regular use, keep this alias
alias v='nvim'

# replace sudo with this functiom
sudo() {
    # check if next argument is 'v'
    if [[ "$1" == "v" ]] ; then
        # remove 'v' from the argument list
        shift

        # call sudo -E nvim on remaining arguments
        command sudo -E nvim "$@"

        # exit the function with the return value of the
        # sudo nvim -E command
        return $?
    fi

    # now check if first argument is a different alias; if so,
    # $expansion will be the alias definition if one exists,
    # or else it will be the empty string
    local expansion="${BASH_ALIASES[$1]}"
    if [[ -n "$expansion" ]] ; then
        # remove the alias from the argument list
        shift

        #if the expansion has variables in it,
        #we need to expand those variables, not
        #just the $expansion variable itself,
        #so we use eval
        eval "command sudo $expansion \"\$@\""

        # exit the function with its return value
        return $?
    fi
    # if we got here, what follows sudo is a
    # normal command, so we execute sudo with the
    # rest of the arguments as is
    command sudo "$@"
}
deleted 65 characters in body
Source Link
frabjous
  • 8.8k
  • 1
  • 35
  • 34

# for regular use, keep this alias
alias v='nvim'

# replace sudo with this functiom
sudo() {
    # check if next argument is 'v'
    if [[ "$1" == "v" ]] ; then
        # remove 'v' from the argument list
        shift

        # call sudo -E nvim on remaining arguments
        command sudo -E nvim "$@"

        # exit the function with the return value of the
        # sudo nvim -E command
        return $?
    fi

    # now check if first argument is a different aliasalias; if so,
    # expansion$expansion will be the alias definition if one exists,
    # or else it will be the empty string
    local expansion="${BASH_ALIASES[$1]}"
    if [[ -n "$expansion" ]] ; then
        # remove the alias from the argument list
        shift

        #if the expansion has variables in it,
        #we need to expand those variables, not
        expansion="$(eval#just echothe $expansion)"

  variable itself,
     # execute it with#so thewe expandeduse aliaseval
        commandeval "command sudo $expansion "$@"\"\$@\""
        
        # exit the function with its return value
        return "$?"
    fi
    # if we got here, what follows sudo is a
    # normal command, so we execute sudo with the
    # rest of the arguments as is
    command sudo "$@"
}

# for regular use, keep this alias
alias v='nvim'

# replace sudo with this functiom
sudo() {
    # check if next argument is 'v'
    if [[ "$1" == "v" ]] ; then
        # remove 'v' from the argument list
        shift

        # call sudo -E nvim on remaining arguments
        command sudo -E nvim "$@"

        # exit the function with the return value of the
        # sudo nvim -E command
        return $?
    fi

    # now check if first argument is a different alias
    # expansion will be the alias definition if one exists,
    # or else it will be the empty string
    local expansion="${BASH_ALIASES[$1]}"
    if [[ -n "$expansion" ]] ; then
        # remove the alias from the argument list
        shift

        #if the expansion has variables in it,
        #we need to expand those variables
        expansion="$(eval echo $expansion)"

        # execute it with the expanded alias
        command sudo $expansion "$@"
        
        # exit the function with its return value
        return "$?"
    fi
    # if we got here, what follows sudo is a
    # normal command, so we execute sudo with the
    # rest of the arguments as is
    command sudo "$@"
}

# for regular use, keep this alias
alias v='nvim'

# replace sudo with this functiom
sudo() {
    # check if next argument is 'v'
    if [[ "$1" == "v" ]] ; then
        # remove 'v' from the argument list
        shift

        # call sudo -E nvim on remaining arguments
        command sudo -E nvim "$@"

        # exit the function with the return value of the
        # sudo nvim -E command
        return $?
    fi

    # now check if first argument is a different alias; if so,
    # $expansion will be the alias definition if one exists,
    # or else it will be the empty string
    local expansion="${BASH_ALIASES[$1]}"
    if [[ -n "$expansion" ]] ; then
        # remove the alias from the argument list
        shift

        #if the expansion has variables in it,
        #we need to expand those variables, not
        #just the $expansion variable itself,
        #so we use eval
        eval "command sudo $expansion \"\$@\""

        # exit the function with its return value
        return "$?"
    fi
    # if we got here, what follows sudo is a
    # normal command, so we execute sudo with the
    # rest of the arguments as is
    command sudo "$@"
}
added 139 characters in body
Source Link
frabjous
  • 8.8k
  • 1
  • 35
  • 34

# for regular use, keep this alias
alias v='nvim'

# replace sudo with this functiom
sudo() {
    # check if next argument is 'v'
    if [[ "$1" == "v" ]] ; then
        # remove 'v' from the argument list
        shift

        # call sudo -E nvim on remaining arguments
        command sudo -E nvim "$@"

        # exit the function with the return value of the
        # sudo nvim -E command
        return $?
    fi

    # now check if first argument is a different alias
    # expansion will be the alias definition if one exists,
    # or else it will be the empty string
    local expansion="${BASH_ALIASES[$1]}"
    if [[ -n "$expansion" ]] ; then
        # remove the alias from the argument list
        shift

        #if the expansion has variables in it,
        #we need to expand those variables
        expansion="$(eval echo $expansion)"

        # execute it with the expanded alias
        command sudo $expansion "$@"
        
        # exit the function with its return value
        return "$?"
    fi
    # if we got here, what follows sudo is a
    # normal command, so we execute sudo with the
    # rest of the arguments as is
    command sudo "$@"
}

# for regular use, keep this alias
alias v='nvim'

# replace sudo with this functiom
sudo() {
    # check if next argument is 'v'
    if [[ "$1" == "v" ]] ; then
        # remove 'v' from the argument list
        shift

        # call sudo -E nvim on remaining arguments
        command sudo -E nvim "$@"

        # exit the function with the return value of the
        # sudo nvim -E command
        return $?
    fi

    # now check if first argument is a different alias
    # expansion will be the alias definition if one exists,
    # or else it will be the empty string
    local expansion="${BASH_ALIASES[$1]}"
    if [[ -n "$expansion" ]] ; then
        # remove the alias from the argument list
        shift

        # execute it with the expanded alias
        command sudo $expansion "$@"
        
        # exit the function with its return value
        return "$?"
    fi
    # if we got here, what follows sudo is a
    # normal command, so we execute sudo with the
    # rest of the arguments as is
    command sudo "$@"
}

# for regular use, keep this alias
alias v='nvim'

# replace sudo with this functiom
sudo() {
    # check if next argument is 'v'
    if [[ "$1" == "v" ]] ; then
        # remove 'v' from the argument list
        shift

        # call sudo -E nvim on remaining arguments
        command sudo -E nvim "$@"

        # exit the function with the return value of the
        # sudo nvim -E command
        return $?
    fi

    # now check if first argument is a different alias
    # expansion will be the alias definition if one exists,
    # or else it will be the empty string
    local expansion="${BASH_ALIASES[$1]}"
    if [[ -n "$expansion" ]] ; then
        # remove the alias from the argument list
        shift

        #if the expansion has variables in it,
        #we need to expand those variables
        expansion="$(eval echo $expansion)"

        # execute it with the expanded alias
        command sudo $expansion "$@"
        
        # exit the function with its return value
        return "$?"
    fi
    # if we got here, what follows sudo is a
    # normal command, so we execute sudo with the
    # rest of the arguments as is
    command sudo "$@"
}
deleted 16 characters in body
Source Link
frabjous
  • 8.8k
  • 1
  • 35
  • 34
Loading
added 29 characters in body
Source Link
frabjous
  • 8.8k
  • 1
  • 35
  • 34
Loading
added 13 characters in body
Source Link
frabjous
  • 8.8k
  • 1
  • 35
  • 34
Loading
Source Link
frabjous
  • 8.8k
  • 1
  • 35
  • 34
Loading