File tree 3 files changed +71
-0
lines changed
3 files changed +71
-0
lines changed Original file line number Diff line number Diff line change @@ -257,6 +257,7 @@ sections = {lualine_a = {'mode'}}
257
257
- ` diff ` (git diff status)
258
258
- ` encoding ` (file encoding)
259
259
- ` fileformat ` (file format)
260
+ - ` filepermissions `
260
261
- ` filename `
261
262
- ` filesize `
262
263
- ` filetype `
@@ -630,6 +631,20 @@ sections = {
630
631
}
631
632
```
632
633
634
+ #### filepermissions component options
635
+
636
+ ``` lua
637
+ sections = {
638
+ lualine_a = {
639
+ {
640
+ ' filepermissions' ,
641
+ octal = false , -- Displays file permissions in octal format if set to true
642
+ }
643
+ }
644
+ }
645
+ }
646
+ ```
647
+
633
648
#### filename component options
634
649
635
650
``` lua
Original file line number Diff line number Diff line change
1
+ -- Copyright (c) 2020-2021 shadmansaleh
2
+ -- MIT license, see LICENSE for more details.
3
+ local M = require (' lualine.component' ):extend ()
4
+ local bit = require (' bit' )
5
+
6
+ -- Initializer
7
+ function M :init (options )
8
+ -- Run super()
9
+ M .super .init (self , options )
10
+ end
11
+
12
+ -- Function that runs every time statusline is updated
13
+ function M :update_status ()
14
+ local curr_filepath = vim .fn .expand (' %' )
15
+ if curr_filepath == ' ' then
16
+ return ' '
17
+ end
18
+
19
+ if not self .options .octal then
20
+ return vim .fn .getfperm (curr_filepath )
21
+ else
22
+ local stat_results = vim .uv .fs_stat (curr_filepath )
23
+ if stat_results == nil then
24
+ return ' '
25
+ end
26
+ local bitmask = 0 b111111111
27
+ local octal_perm = bit .band (stat_results .mode , bitmask )
28
+ return string.format (' o%o' , octal_perm )
29
+ end
30
+ end
31
+
32
+ return M
Original file line number Diff line number Diff line change @@ -585,6 +585,30 @@ describe('FileSize component', function()
585
585
end )
586
586
end )
587
587
588
+ describe (' Filepermissions componnet' , function ()
589
+ it (' can show octal permissions' , function ()
590
+ local opts = build_component_opts {
591
+ octal = true ,
592
+ }
593
+ vim .cmd (' :e test-file.txt' )
594
+ assert_component (' filepermissions' , opts , ' ' )
595
+ vim .cmd (' :w' )
596
+ vim .fn .setfperm (" test-file.txt" , " rwxrwxrwx" )
597
+ assert_component (' filename' , opts , ' o777' )
598
+ end )
599
+
600
+ it (' can show regular permissions' , function ()
601
+ local opts = build_component_opts {
602
+ octal = false ,
603
+ }
604
+ vim .cmd (' :e test-file.txt' )
605
+ assert_component (' filepermissions' , opts , ' ' )
606
+ vim .cmd (' :w' )
607
+ vim .fn .setfperm (" test-file.txt" , " rwxrwxrwx" )
608
+ assert_component (' filename' , opts , ' rwxrwxrwx' )
609
+ end )
610
+ end )
611
+
588
612
describe (' Filename component' , function ()
589
613
it (' works' , function ()
590
614
local opts = build_component_opts {
You can’t perform that action at this time.
0 commit comments