James Whiteley
James Whiteley

Reputation: 3474

Combining functions in bash

I have written two functions into my ~/.bash_aliases file; one returns the current working folder (everything after the last / in the directory path), and one sets the terminal tab:

function set-location { printf "\e]2;$1\a"; }
function get-location {
    local location=${PWD##*/}
    echo "$location"
}

Say I am in directory james/foo/bar. Combining the two functions, I expect the terminal window to be set to bar. However, I cannot work out how to combine them effectively. I have tried the following to no avail, though I am just guessing what would work at this point:

set-location get-location # terminal title: get-location
set-location $get-location # terminal title: -location
set-location ${get-location} # terminal title: location
set-location "${get-location}" # terminal title: location
get-location | set-location # terminal title: Terminal

How do I combine these two functions in a single line, so that I can set the location to be the result of get-location?

Upvotes: 0

Views: 332

Answers (1)

choroba
choroba

Reputation: 241998

Use command substitution

set-location "$(get-location)"

Upvotes: 2

Related Questions