5

Inside the terminal when I type resize -s 50 50 terminal output is changed as rows 50 and columns 50.

enter image description here

But after closing the window and reopen terminal doesn't reflect the changes.

enter image description here

I want to open the terminal all time as rows 50 and columns 50.

I know this can be done using terminal Edit->Profile Preference->General setting with changing the rows and columns number, but I want to do this in CLI, because I have to do this inside a big script.

My .bashrc

# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples

# If not running interactively, don't do anything
case $- in
    *i*) ;;
      *) return;;
esac

# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth

# append to the history file, don't overwrite it
shopt -s histappend

# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000

# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize

# If set, the pattern "**" used in a pathname expansion context will
# match all files and zero or more directories and subdirectories.
#shopt -s globstar

# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"

# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
    debian_chroot=$(cat /etc/debian_chroot)
fi

# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
    xterm-color) color_prompt=yes;;
esac

# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
#force_color_prompt=yes

if [ -n "$force_color_prompt" ]; then
    if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
    # We have color support; assume it's compliant with Ecma-48
    # (ISO/IEC-6429). (Lack of such support is extremely rare, and such
    # a case would tend to support setf rather than setaf.)
    color_prompt=yes
    else
    color_prompt=
    fi
fi

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
    PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
    ;;
*)
    ;;
esac

# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
    test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
    alias ls='ls --color=auto'
    #alias dir='dir --color=auto'
    #alias vdir='vdir --color=auto'

    alias grep='grep --color=auto'
    alias fgrep='fgrep --color=auto'
    alias egrep='egrep --color=auto'
fi

# some more ls aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'

# Add an "alert" alias for long running commands.  Use like so:
#   sleep 10; alert
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'

# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if ! shopt -oq posix; then
  if [ -f /usr/share/bash-completion/bash_completion ]; then
    . /usr/share/bash-completion/bash_completion
  elif [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
  fi
fi
##########################################################################################################
#alhelal customization
resize -s 50 50
#resize -s 50 50 >/dev/null
##########################################################################################################

Result after pressing CtrlAltT

enter image description here

The default terminal size of Ubuntu is smaller than my monitor. When I install new OS I have to change many setting(customization), installation many software. So, I am making a script that do the customization and install all stuffs without my interruption. e.g.,

  • change terminal window size
  • make shortkey
  • install firefox addons
  • install software
  • clone git repository.
alhelal
  • 2,621

4 Answers4

10

First option

You can always run resize -s 50 50 at terminal launch using ~/.bashrc file. And to hide the command output just redirect it to the /dev/null device.

In other words, to resize the terminal using command line use:

echo "resize -s 50 50 >/dev/null" >> ~/.bashrc

Second option

After messing around with dconf-editor I believe I found exactly what you're searching for. gnome-terminal store its setting in dconf instead of config files. First you have to select the currently active terminal profile running this command:

currentprofile=$(gsettings get org.gnome.Terminal.ProfilesList default)

Then to set 50 rows as default run:

gsettings set org.gnome.Terminal.Legacy.Profile:/org/gnome/terminal/legacy/profiles:/:${currentprofile:1:-1}/ default-size-rows 50

And similarly for the columns:

gsettings set org.gnome.Terminal.Legacy.Profile:/org/gnome/terminal/legacy/profiles:/:${currentprofile:1:-1}/ default-size-columns 50

Done. Hope this helps

  • I put resize -s 50 50 >/dev/null in top of .bashrc but doesn't affect terminal size. – alhelal May 17 '18 at 17:11
  • it doesn't work also in last line. – alhelal May 17 '18 at 17:31
  • @alhelal I updated my answer, try the second option – Eskander Bejaoui May 17 '18 at 21:38
  • $ currentprofile=$(gsettings get org.gnome.Terminal.ProfilesList default) No such schema 'org.gnome.Terminal.ProfilesList' – alhelal May 18 '18 at 03:14
  • 2
    +1. Thanks for finding how to use gsettings and showing a solution :-) – sudodus May 18 '18 at 16:47
  • By the way, the original and simple resize -s 50 50 works for me in Ubuntu 18.04 LTS. I can't understand why it does not work for you, @alhelal. Please add it to ~/.bashrc and open a new gnome-terminal. What happens? This setting should survive shutdown and reboot too. – sudodus May 18 '18 at 17:02
  • @sudodus see https://ibb.co/k3PGWT – alhelal May 19 '18 at 03:56
  • @sudodus my .bashrc https://paste.ubuntu.com/p/YCkrY3Qdmp/ – alhelal May 19 '18 at 03:59
  • 1
    @sudodus It works for me also when I unselected use custom default terminal size https://ibb.co/bAGMWT Thank you. – alhelal May 19 '18 at 04:13
  • @sudodus Should I delete this question or add solution? – alhelal May 19 '18 at 04:15
  • @alhelal, You are welcome to write an answer to your own question and 'accept' it (click on the tick icon). Please describe your solution with as many details as you think are helpful for other people who want to do the same thing. -- If you find @SkanderBejaoui's answer helpful, please upvote it by clicking on the ^icon. – sudodus May 19 '18 at 05:58
3

gnome-terminal

If I understand correctly, you are using standard Ubuntu and gnome-terminal, so you can use the following command line in your script,

gnome-terminal --geometry <columns>x<rows>

for example

gnome-terminal --geometry 135x45

You find the available options in man gnome-terminal.

xterm

The corresponding command line for good old xterm is

xterm -geometry 135x45

where you can add details to set the absolute position on the desktop (in pixels). Test these command lines,

xterm -geometry 90x25+0+0  # top left
xterm -geometry 90x25+0-0  # bottom left
xterm -geometry 90x25-0+0  # top right
xterm -geometry 90x25-0-0  # bottom right

and you can select other values than 0 for an arbitrary location.

You find the available options in man xterm (there are a lot of options).

dessert
  • 39,982
sudodus
  • 46,324
  • 5
  • 88
  • 152
  • yes, you understand. But I want to type this command each time. When I open terminal automatically should execute this. Keep in mind that I have to done all things in CLI because I have to do this inside a bigger script. – alhelal May 17 '18 at 17:39
  • I thought that you wanted the script to open the terminal window and decide its size, and in that case you need not type all this. Simply put the whole command line in the script. -- On the other hand, if you want to do it manually, you can use an alias (interactively) or use a variable in the script to avoid typing more than necessary. – sudodus May 17 '18 at 17:52
  • 1
    I think the OP is asking for the CLI equivalent of Edit->Profile Preference->General settings. Maybe some gsettings call or something. – PerlDuck May 17 '18 at 18:13
  • 2
    Maybe you are right. Let us wait for the OP to tell us what they want. – sudodus May 17 '18 at 18:18
  • @PerlDuck Yes. I have already wrote this in my edited question. – alhelal May 18 '18 at 03:17
  • 1
    @sudodus Yes. I have already wrote this in my edited question – alhelal May 18 '18 at 03:17
  • @alhelal, I see. Well I have not used gsettings, so I suggest that someone who knows how to use it can write an answer about that. Otherwise this AskUbuntu link may help – sudodus May 18 '18 at 10:30
  • I still don't understand how you intend to use this. 1. Why are you modifying the settings of gnome-terminal via a script, if you intend to start gnome-terminal manually? 2. Is this intended for other people too, or only for yourself? 3. Would an alias solve the problem for you? I mean that the script could store the alias in ~/.bashrc. 4. Would a desktop file solve the problem for you? I mean that you can have a desktop file, that opens the size of gnome-terminal, that you want. – sudodus May 18 '18 at 10:44
  • @sudodus The default terminal size small than my monitor. When I install new OS I have to change many setting(customization), installation many software. So, I am making a script that do the customization and install all stuffs without my interruption. – alhelal May 18 '18 at 14:06
  • @alhelal did you think about using a separate /home partition? i it should keep all your customizations across OS reinstalls – Eskander Bejaoui May 19 '18 at 04:11
  • @SkanderBejaoui It works for me also when I unselected use custom default terminal size ibb.co/bAGMWT – alhelal May 19 '18 at 04:14
  • @SkanderBejaoui Should I delete this question or add solution? – alhelal May 19 '18 at 04:19
3

It works for me when I unselected use custom default terminal size

enter image description here

enter image description here

Add add

resize -s 50 50 > /dev/null  

to ~/.bashrc

After pressing CtrlAltT

enter image description here

alhelal
  • 2,621
0

See also: https://stackoverflow.com/a/288537/1506858

Copied from the link above:


Use the wmctrl command:

To list the windows:

$ wmctrl -l
0x00c00003 -1 rgamble-desktop Bottom Expanded Edge Panel
0x00c00031 -1 rgamble-desktop Top Expanded Edge Panel
0x00e00022 -1 rgamble-desktop Desktop
0x0260007c  0 rgamble-desktop Google - Mozilla Firefox

To resize a window based on its title:

wmctrl -r Firefox -e 0,0,0,640,480

The arguments to the resize option are gravity,X,Y,width,height so this will place the window at the top-left corner of the screen and resize it to 640X480.